이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define tr(it,a) for(auto it:a)
#define pob pop_back
#define pf push_front
#define pof pop_front
#define umin(x,y) (x=min(x,(y)))
#define umax(x,y) (x=max(x,(y)))
//#define mid ((l+r)/2)
#define lch (idx*2+1)
#define rch (idx*2+2)
//
#include<bits/stdc++.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
#define rep(i,j,k) for(int i=(j);i<(k);++i)
#define rrep(i,j,k) for(int i=int(j)-1;i>=(k);--i)
#define all(a) a.begin(),a.end()
#define pb push_back
#define f first
#define s second
#define endl '\n'
// #define __debug
#ifdef __debug
#define ios (void)0
#define pr(...) cerr<<__VA_ARGS__
#define ar(a,s,t) {rep(zy,s,t)pr(a[zy]<<' ');pr(endl);}
#else
#define ios cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
#define pr(...) (void)0
#define ar(...) (void)0
#endif
//
const int maxn=2e5+9,inf=1ll<<40;
int n,m,ll=0,rr=0,sum=0,res=-inf;
pii a[maxn];
multiset<int>s1,s2;
void mnt(){
if(s2.size()<m){
auto it=--s1.end();
s2.insert(*it),sum+=*it,s1.erase(it);
}else if(s2.size()>m){
auto it=s2.begin();
s1.insert(*it),s2.erase(it),sum-=*it;
}
}
void ins(int x){
s2.insert(x),sum+=x;
mnt();
}
void rem(int x){
if(s1.count(x))s1.erase(s1.find(x));
else s2.erase(s2.find(x)),sum-=x,mnt();
}
void sol(int l1,int r1,int l2,int r2){
if(l1>r1)return;
int mid=(l1+r1)/2,k=max(mid,l2);
while(rr<k)ins(a[rr++].s);
while(ll>mid)ins(a[--ll].s);
while(rr>k)rem(a[--rr].s);
while(ll<mid)rem(a[ll++].s);
pii opt={sum-2*(a[l2-1].f-a[mid].f),k};
rep(i,k,r2){
ins(a[rr++].s);
umax(opt,pii(sum-2*(a[i].f-a[mid].f),i+1));
}
umax(res,opt.f);
sol(l1,mid-1,l2,opt.s);
sol(mid+1,r1,opt.s,r2);
}
main(){
ios;
cin>>n>>m;
rep(i,0,n)cin>>a[i].s>>a[i].f;
sort(a,a+n);
rep(i,0,m)s2.insert(-inf),sum-=inf;
sol(0,n-m,m,n);
cout<<res<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'void mnt()':
cake3.cpp:45:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(s2.size()<m){
~~~~~~~~~^~
cake3.cpp:48:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
}else if(s2.size()>m){
~~~~~~~~~^~
cake3.cpp: At global scope:
cake3.cpp:81:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |