Submission #335878

# Submission time Handle Problem Language Result Execution time Memory
335878 2020-12-14T07:43:44 Z sumit_kk10 Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
 
long long int besthub(int r, int l, int a[], long long int b){
	int j = (r/2) - 1, k = (r/2) + 1, i = r/2;
	long long int budget = b, how_many = 1; 
	while(budget >= 0){
		if(j < 0 and k >= r) break;
		if(abs(a[j] - a[i]) <= abs(a[k] - a[i]) and abs(a[j] - a[i]) <= budget and j >= 0){
			budget -= abs(a[j] - a[i]);
			++how_many;
			--j;
		}
		else if(abs(a[k] - a[i]) <= abs(a[j] - a[i]) and abs(a[k] - a[i]) <= budget and k < r){
			budget -= abs(a[k] - a[i]);
			++how_many;
			++k;
		}
		else
			break;
	}
	j = ((r + 1)/2) - 1, k = ((r + 1)/2) + 1, i = (r  + 1) / 2;
	budget = b;
	long long int how_many1 = 1;
	while(budget >= 0){
		if(j < 0 and k >= r) break;
		if(abs(a[j] - a[i]) <= abs(a[k] - a[i]) and abs(a[j] - a[i]) <= budget and j >= 0){
			budget -= abs(a[j] - a[i]);
			++how_many1;
			--j;
		}
		else if(abs(a[k] - a[i]) <= abs(a[j] - a[i]) and abs(a[k] - a[i]) <= budget and k < r){
			budget -= abs(a[k] - a[i]);
			++how_many1;
			++k;
		}
		else
			break;
	}
	j = ((r - 1)/2) - 1, k = ((r - 1)/2) + 1, i = (r - 1) / 2;
	budget = b;
	long long int how_many2 = 1;
	while(budget >= 0){
		if(j < 0 and k >= r) break;
		if(abs(a[j] - a[i]) <= abs(a[k] - a[i]) and abs(a[j] - a[i]) <= budget and j >= 0){
			budget -= abs(a[j] - a[i]);
			++how_many2;
			--j;
		}
		else if(abs(a[k] - a[i]) <= abs(a[j] - a[i]) and abs(a[k] - a[i]) <= budget and k < r){
			budget -= abs(a[k] - a[i]);
			++how_many2;
			++k;
		}
		else
			break;
	}
	return max({how_many1, how_many, how_many2});
}

int main(){
    int n, l;
    long long int b;
    cin >> n >> l >> b;
    int a[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    cout << besthub(n, l, a, b) << '\n';
}

Compilation message

/tmp/ccPoUI88.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccgdpVDY.o:ricehub.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status