Submission #97381

# Submission time Handle Problem Language Result Execution time Memory
97381 2019-02-15T16:34:40 Z Shafin666 Rice Hub (IOI11_ricehub) C++14
0 / 100
7 ms 848 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;

ll besthub(int r, int l, int x[], ll b) {
	ll answer = 0;
	ll inf = 1e9+7;

	//sort(x, x+r);

		ll c = x[r/2];
		vector<ll> v;

		for(ll i = 0; i < r; i++) v.pb(abs(x[i]-c));
		v.pb(inf);

		ll maxlen = 0;

		ll k = 0, s = 0;
		for(ll i = 0; i < r+1; i++) {
			if(s + v[i] <= b) {
				s += v[i];
				k++;
			} 
			else if(v[i] > b) {
				maxlen = max(maxlen, k);
				s = 0; k = 0;
			}
			else {
				maxlen = max(maxlen, k);
				s = v[i];
				k = 1;
			}
		}
	if(r > 2) {
		c = x[r/2+1];
		v.clear();

		for(ll i = 0; i < r; i++) v.pb(abs(x[i]-c));
		v.pb(inf);

		k = 0, s = 0;
		for(ll i = 0; i < r+1; i++) {
			if(s + v[i] <= b) {
				s += v[i];
				k++;
			} 
			else if(v[i] > b) {
				maxlen = max(maxlen, k);
				s = 0; k = 0;
			}
			else {
				maxlen = max(maxlen, k);
				s = v[i];
				k = 1;
			}
		}
	}
	return maxlen;
}
/*
int main()
{	
	int x[1] = {1};
	cout << besthub(1, 20, x, 6) << endl;

    return 0;
}*/

Compilation message

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