Submission #228397

# Submission time Handle Problem Language Result Execution time Memory
228397 2020-04-30T22:25:24 Z tushar_2658 Rice Hub (IOI11_ricehub) C++14
0 / 100
109 ms 708 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;

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;
  for(int i = 0; i < n; ++i){
  	ll mid = a[i];
  	int l = i, r = i;
  	ll left = B;
  	int done = 1;
  	while(left > 0 && r < n && l >= 0){
  		ll nxt_l = LLONG_MAX;
  		if(l > 0){
  			nxt_l = a[l] - a[l - 1];
  		}
  		ll nxt_r = LLONG_MAX;
  		if(r < n - 1){
  			nxt_r = a[r + 1] - a[r];
  		}
  		if(nxt_l < nxt_r){
  			done++;
  			left -= nxt_l;
  			if(left < 0){
  				done--;
  				break;
  			}
  			--l;
  		}else {
  			done++;
  			left -= nxt_r;
  			if(left < 0){
  				done--;
  				break;
  			}
  			++r;
  		}
  	}
  	ans = max(ans, done);
  }
  return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:31:7: warning: unused variable 'mid' [-Wunused-variable]
    ll mid = a[i];
       ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Incorrect 4 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 708 KB Output isn't correct
2 Halted 0 ms 0 KB -