Submission #851564

#TimeUsernameProblemLanguageResultExecution timeMemory
851564abcvuitunggioSails (IOI07_sails)C++17
45 / 100
21 ms2392 KiB
#include <bits/stdc++.h> using namespace std; int n,h,k,sum,cnt[100002],a[100001]; long long res; int main(){ ios_base::sync_with_stdio(NULL);cin.tie(nullptr); cin >> n; cnt[1]=n; while (n--){ cin >> h >> k; cnt[h+1]--; sum+=k; } for (int i=1;i<=100001;i++){ cnt[i]+=cnt[i-1]; if (!a[cnt[i]]) a[cnt[i]]=i; } for (int i=1;i<=100000;i++) if (!a[i]) a[i]=a[i-1]; for (int i=100000;i>=1;i--) cnt[i]+=cnt[i+1]; for (int i=1;i<=100000;i++){ int l=0,r=100000,kq=-1; while (l<=r){ int mid=(l+r)>>1; if (cnt[max(a[mid],i)]+mid*max(a[mid]-i,0)>=sum){ kq=mid; r=mid-1; } else l=mid+1; } sum-=kq; res+=kq*(kq-1)/2; } cout << res; }
#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...