Submission #54482

#TimeUsernameProblemLanguageResultExecution timeMemory
54482DiuvenSails (IOI07_sails)C++11
100 / 100
115 ms10620 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MX=100010, inf=2e9; int n; pii P[MX]; multiset<int> X; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i=1; i<=n; i++) cin>>P[i].first>>P[i].second; sort(P+1, P+n+1); for(int i=1; i<=n; i++) X.insert(0); for(int i=1; i<=n; i++){ int h,cnt; tie(h,cnt)=P[i]; auto itu=X.lower_bound(h-cnt+1); auto itd=itu; itd--; if(itu==X.end()){ int tmp=*itd; X.erase(itd); X.insert(tmp+cnt); } else{ cnt-=h-(*itu); X.erase(itu); X.insert(h); int tmp=*itd; X.erase(itd); X.insert(tmp+cnt); } } ll prv=0, ans=0, cnt=n; for(int x:X){ ans+=(x-prv)*cnt*(cnt-1)/2; prv=x; cnt--; } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...