Submission #62622

#TimeUsernameProblemLanguageResultExecution timeMemory
62622mhndHoliday (IOI14_holiday)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5+50;
const ll oo = 1e18;
const ll mod = 1e9+7;

ll f[101],ans;

long long int findMaxAttraction(int n, int start, int d, int a[]){
	if(n <= 3000){
		multiset<int> q;
		ll sum = 0;
		for(int i=start;i<n;i++){
			ll cur = d-(i-start);
			if(!cur)break;
			q.insert(a[i]);
			sum += a[i];
			while(q.size() && q.size() > cur){
				sum -= *q.begin();
				q.erase(q.begin());
			}
			ans = max(ans,sum);
		}
		sum = 0;
		q.clear();
		for(int i=start;i>=0;i--){
			ll cur = d-(start-i);
			if(!cur)break;
			q.insert(a[i]);
			sum += a[i];
			while(q.size() && q.size() > cur){
				sum -= *q.begin();
				q.erase(q.begin());
			}
			ans = max(ans,sum);
		}
		for(int i=start;i<n;i++){
			sum = 0;
			q.clear();
			ll cur = d-(i-start);
			if(!cur)break;
			for(int j=i;j>=0;j--){
				if(!cur)break;
				q.insert(a[j]);
				sum+=a[j];
				while(q.size() && q.size() > cur){
					sum -= *q.begin();
					q.erase(q.begin());
				}
				cur--;
				ans = max(ans,sum);
			}
		}
		for(int i=start;i>=0;i--){
			sum = 0;
			q.clear();
			ll cur = d-(start-i);
			if(!cur)break;
			for(int j=i;j<n;j++){
				if(!cur)break;
				q.insert(a[j]);
				sum+=a[j];
				while(q.size() && q.size() > cur){
					sum -= *q.begin();
					q.erase(q.begin());
				}
				cur--;
				ans = max(ans,sum);
			}
		}
		return ans;
	}
	for(int i=0;i<n;i++){
		f[a[i]]++;
		if(i > d)break;
		int k = d - i,cur=0;
		for(int j=100;j>=0&&k;j--){
			int v = min(k*1ll,f[j]);
			k-=v;
			cur += j*v;
		}
		ans = max(ans,cur*1ll);
	}
	return ans;
}

int x[N];
int main(){
	int n,start,d;
	cin>>n>>start>>d;
	for(int i=0;i<n;i++)cin>>x[i];
	cout << findMaxAttraction(n,start,d,x) << endl;
}

Compilation message (stderr)

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:22:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(q.size() && q.size() > cur){
                      ~~~~~~~~~^~~~~
holiday.cpp:35:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(q.size() && q.size() > cur){
                      ~~~~~~~~~^~~~~
holiday.cpp:50:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(q.size() && q.size() > cur){
                       ~~~~~~~~~^~~~~
holiday.cpp:67:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(q.size() && q.size() > cur){
                       ~~~~~~~~~^~~~~
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
     int i, n_s;
            ^~~
/tmp/cc3zvTW6.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccUMQ8EK.o:holiday.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status