Submission #964663

# Submission time Handle Problem Language Result Execution time Memory
964663 2024-04-17T09:51:57 Z Ahmed57 Holiday (IOI14_holiday) C++17
0 / 100
213 ms 8864 KB
#include "holiday.h"

#include "bits/stdc++.h"
using namespace std;
int ST , D , N;
int L = -1 , R = -1;
long long cur = 0;
multiset<int> lrg,sml;
long long ARR[200001];
long long ma = -1e18;
void fix(int l,int r,int sz){
    if(L==-1&&R==-1){
        for(int i = l;i<=r;i++){
            lrg.insert(ARR[i]);
            cur+=ARR[i];
        }
        L = l;
        R = r;
    }else{
        while(L>l){
            L--;
            lrg.insert(ARR[L]);
            cur+=ARR[L];
        }
        while(R<r){
            R++;
            lrg.insert(ARR[R]);
            cur+=ARR[R];
        }
        while(L<l){
            auto it = lrg.lower_bound(ARR[L]);
            if(it!=lrg.end()&&(*it)==ARR[L]){
                cur-=ARR[L];
                lrg.erase(it);
            }else{
                sml.erase(sml.lower_bound(ARR[L]));
            }
            L++;
        }
        while(R>r){
            auto it = lrg.lower_bound(ARR[R]);
            if(it!=lrg.end()&&(*it)==ARR[R]){
                cur-=ARR[R];
                lrg.erase(it);
            }else{
                sml.erase(sml.lower_bound(ARR[R]));
            }
            R--;
        }
    }
    while(sml.size()&&lrg.size()&&*(lrg.begin())<*(--sml.end())){
        int a = (*lrg.begin()), b = *(--sml.end());
        cur+=b-a;
        lrg.erase(lrg.begin());
        sml.erase((--sml.end()));
        lrg.insert(b);
        sml.insert(a);
    }
    while(lrg.size()<sz&&sml.size()){
        cur+=*(--sml.end());
        lrg.insert(*(--sml.end()));
        sml.erase((--sml.end()));
    }
    while(lrg.size()>sz){
        cur-=(*lrg.begin());
        sml.insert(*(lrg.begin()));
        lrg.erase(*(lrg.begin()));
    }
}
void dc(int l,int r,int lq,int rq){
    if(l>r)return ;
    int mid = (l+r)/2;
    long long ans = -1e18 ;
    int pos = -1;
    for(int i = lq;i<=rq;i++){
        int di = D-min((ST-mid)*2+(i-ST),(i-ST)*2+(ST-mid));
        cout<<mid<<" "<<i<<" "<<di<<endl;
        if(di>=0){
        fix(mid,i,di);
        if(ans<cur){
            ans = cur;
            pos = i;
        }
        }
    }
    ma = max(ma,ans);
    dc(l,mid-1,lq,min(rq,pos));
    dc(mid+1,r,max(lq,pos),rq);
}
long long findMaxAttraction(int n,int st,int d,int arr[]){
    for(int i = 0;i<n;i++)ARR[i] = arr[i];
    ST = st;
    D = d;
    N = n;
    dc(0,st,st,n);
    return ma;
}

Compilation message

holiday.cpp: In function 'void fix(int, int, int)':
holiday.cpp:59:21: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |     while(lrg.size()<sz&&sml.size()){
      |           ~~~~~~~~~~^~~
holiday.cpp:64:21: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     while(lrg.size()>sz){
      |           ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 7968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 213 ms 8864 KB Output isn't correct
2 Halted 0 ms 0 KB -