답안 #947976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947976 2024-03-17T10:57:27 Z yeediot 휴가 (IOI14_holiday) C++14
100 / 100
616 ms 7108 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){
    //cerr<<l<<' '<<r<<' '<<ql<<' '<<qr<<'\n';
    if(l>r)return;
    long long mm=(l+r)/2;
    long long mx=0;
    long long best=ql;
    for(long long i=qr;i>=ql;i--){
        long long x=min(mm-i+1,d-(min(st-i,mm-st)+mm-i));
        //cerr<<x<<'\n';
        if(x<0)break;
        sir(i,mm,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);
    solve(st,n-1,0,st);
    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:
 
 */















 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 740 KB Output is correct
3 Correct 0 ms 600 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
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 6200 KB Output is correct
2 Correct 78 ms 6236 KB Output is correct
3 Correct 77 ms 6232 KB Output is correct
4 Correct 78 ms 6208 KB Output is correct
5 Correct 206 ms 5724 KB Output is correct
6 Correct 42 ms 2140 KB Output is correct
7 Correct 88 ms 3856 KB Output is correct
8 Correct 139 ms 4188 KB Output is correct
9 Correct 26 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 7 ms 860 KB Output is correct
5 Correct 8 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 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 6236 KB Output is correct
2 Correct 85 ms 6228 KB Output is correct
3 Correct 94 ms 3276 KB Output is correct
4 Correct 6 ms 856 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 614 ms 6972 KB Output is correct
9 Correct 616 ms 7108 KB Output is correct