Submission #228394

# Submission time Handle Problem Language Result Execution time Memory
228394 2020-04-30T21:53:25 Z tushar_2658 Rice Hub (IOI11_ricehub) C++14
17 / 100
1000 ms 1920 KB
#include "ricehub.h"
#include "bits/stdc++.h"
using namespace std;

const int maxn = 100005;
using ll = long long;

int a[maxn];
ll lim;
vector<ll> p;
int n;

bool can(int x){
	ll tot = LLONG_MAX;
	for(int i = x - 1; i < n; ++i){
		int l = i - x + 1;
		ll val;
		if(l != 0){
			val = p[i] - p[l - 1];
		}else {
			val = p[i];
		}
		val /= x;
		ll need = 0;
		for(int j = l; j <= i; ++j){
			need += llabs(a[j] - val);
		}
		tot = min(tot, need);
		need = 0;
		for(int j = l; j <= i; ++j){
			need += llabs(a[j] - (val + 1));
		}
		tot = min(tot, need);
	}
	if(tot <= lim)return 1;
	else return 0;
}

int besthub(int R, int L, int X[], long long B)
{
	n = R;
	lim = B;
	p.resize(R);
	for(int i = 0; i < R; ++i){
		a[i] = X[i];
	}
	sort(a, a + R);
	for(int i = 0; i < R; ++i){
		if(i == 0){
			p[i] = a[i];
		}else {
			p[i] = p[i - 1] + a[i];
		}
	}
  int ans = 0;
  int lo = 1, hi = R;
  while(lo <= hi){
  	int mid = (lo + hi) >> 1;
  	if(can(mid)){
  		ans = mid;
  		lo = mid + 1;
  	}else {
  		hi = mid - 1;
  	}
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 308 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Incorrect 6 ms 384 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 53 ms 384 KB Output is correct
22 Correct 53 ms 384 KB Output is correct
23 Correct 39 ms 384 KB Output is correct
24 Correct 39 ms 384 KB Output is correct
25 Correct 39 ms 384 KB Output is correct
26 Correct 39 ms 384 KB Output is correct
27 Incorrect 149 ms 384 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 575 ms 800 KB Output is correct
2 Correct 573 ms 764 KB Output is correct
3 Execution timed out 1087 ms 1920 KB Time limit exceeded
4 Halted 0 ms 0 KB -