Submission #412431

#TimeUsernameProblemLanguageResultExecution timeMemory
412431DaktoSails (IOI07_sails)C++17
0 / 100
78 ms3364 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<pair<int,int>> v(n); for(int i=0; i<n; i++) cin>>v[i].first>>v[i].second; long long res=1e16; long long s=0; for(auto i:v) s+=i.second; vector<long long> da(100000,0), cnt(100050,0), nv(100005,0); for(auto i:v){ da[i.first]++; da[i.first-i.second]--; cnt[i.first]++; } for(int i=100000; i>=1; i--){ nv[i]=nv[i+1]+da[i]; cnt[i]+=cnt[i+1]; } auto check=[&](long long c){ long long v=0; long long tr=0; long long ts=0; for(int i=100000; i>=1; i--){ v+=da[i]; int d=min(min(v,cnt[i]),c-(s-ts<=i?1:0)); tr+=d*(d-1)/2; v-=d; ts+=nv[i]; } if(!v) res=min(res,tr); return v==0; }; int l=1, r=1e5; while(l<r){ int m=(l+r)/2; if(check(m)) r=m; else l=m+1; } cout<<res<<endl; }
#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...