# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
947974 |
2024-03-17T10:51:41 Z |
yeediot |
Holiday (IOI14_holiday) |
C++14 |
|
96 ms |
6236 KB |
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#else
void setio(){}
#endif
const long long mxn=1e5+5;
multiset<long long>bg,sm;
long long n,st,d,L,R;
long long cur,v[mxn];
void sir(long l,long r,long k){
while(L>l){
bg.insert(v[--L]);
cur+=v[L];
}
while(R<r){
bg.insert(v[++R]);
cur+=v[R];
}
while(L<l){
if(bg.find(v[L])!=bg.end()){
cur-=v[L];
bg.erase(bg.find(v[L]));
}
else{
sm.erase(sm.find(v[L]));
}
L++;
}
while(R>r){
if(bg.find(v[R])!=bg.end()){
cur-=v[R];
bg.erase(bg.find(v[R]));
}
else{
sm.erase(sm.find(v[R]));
}
R--;
}
while(sz(bg)>k){
cur-=*bg.begin();
sm.insert(*bg.begin());
bg.erase(bg.begin());
}
while(sz(bg)<k){
cur+=*prev(sm.end());
bg.insert(*prev(sm.end()));
sm.erase(prev(sm.end()));
}
}
long long ans;
void solve(long long l,long long r,long long ql,long long qr){
if(l>r)return;
long long mm=(l+r)/2;
long long mx=0;
long long best=ql;
for(long long i=ql;i<=qr;i++){
long long x=min(i-mm+1,d-(min(i-st,st-mm)+i-mm));
if(x<0)break;
sir(mm,i,x);
if(cur>=mx){
best=i;
mx=cur;
}
}
chmax(ans,mx);
solve(l,mm-1,ql,best);
solve(mm+1,r,best,qr);
}
long long findMaxAttraction(int N,int ST,int D,int a[]){
n=N,st=ST,d=D,cur=0,L=0,R=n-1;
for(long long i=0;i<n;i++){
v[i]=a[i];
bg.insert(v[i]);
cur+=v[i];
}
solve(0,st,st,n-1);
return ans;
}
#ifdef local
int main(){
setio();
int a,b,c;
cin>>a>>b>>c;
int x[n];
for(int i=0;i<a;i++){
cin>>x[i];
}
cout<<findMaxAttraction(a,b,c,x)<<'\n';
}
#else
#endif
/*
input:
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
6236 KB |
Output is correct |
2 |
Correct |
38 ms |
6224 KB |
Output is correct |
3 |
Correct |
38 ms |
6144 KB |
Output is correct |
4 |
Correct |
38 ms |
6228 KB |
Output is correct |
5 |
Correct |
61 ms |
5724 KB |
Output is correct |
6 |
Correct |
15 ms |
2136 KB |
Output is correct |
7 |
Correct |
29 ms |
3420 KB |
Output is correct |
8 |
Correct |
40 ms |
4188 KB |
Output is correct |
9 |
Correct |
10 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
784 KB |
Output is correct |
4 |
Correct |
9 ms |
984 KB |
Output is correct |
5 |
Correct |
6 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
6236 KB |
Output is correct |
2 |
Correct |
42 ms |
6232 KB |
Output is correct |
3 |
Correct |
96 ms |
3272 KB |
Output is correct |
4 |
Incorrect |
7 ms |
860 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |