Submission #468846

# Submission time Handle Problem Language Result Execution time Memory
468846 2021-08-29T20:38:03 Z pere_gil Rice Hub (IOI11_ricehub) C++14
0 / 100
4 ms 332 KB
#include "ricehub.h"
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

ll get_sum(int l, int r, vector<int> &sum){
	return (l==0) ? sum[r] : sum[r]-sum[l-1];
}

bool check(int l, int r, ll b, int v[], vector<int> &sum){
	int med=(l+r)>>1;
	ll act=v[med]*(med-l+1)-get_sum(l,med,sum);
	act+=get_sum(med,r,sum)-v[med]*(r-med+1);
	return act<=b;
}

int besthub(int n, int dist, int v[], ll b){
	vector<int> sum(n);
	sum[0]=v[0];
	for(int i=1;i<n;i++)
		sum[i]=sum[i-1]+v[i];

	int res=0;
	for(int i=0;i<n;i++){
		int l=i,r=n-1,act=0;
		while(l+1<r){
			int med=(l+r)>>1;
			if(check(i,med,b,v,sum)) l=med;
			else r=med;
		}
		res=max(res,r-i+1);
	}
	return res;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:26:17: warning: unused variable 'act' [-Wunused-variable]
   26 |   int l=i,r=n-1,act=0;
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -