Submission #1104977

#TimeUsernameProblemLanguageResultExecution timeMemory
1104977FaggiSails (IOI07_sails)C++11
25 / 100
44 ms4936 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; vector<ll>tamDP; vector<ll>calcs; ll tam; bool can(vector<ll> dp,ll x) { ll ma, sob, i; for(i=tam; i>0; i--) { ma=min(x,tamDP[i]); sob=0; if(dp[i]>ma) { sob=dp[i]-ma; dp[i]=ma; if(i>1) dp[i-1]+=sob; else return 0; } } return 1; } ll calc(vector<ll> & dp, ll x) { ll ma, sob, i, res=0; for(i=tam; i>0; i--) { ma=min(x,tamDP[i]); sob=0; if(dp[i]>ma) { sob=dp[i]-ma; dp[i]=ma; dp[i-1]+=sob; } } for(i=tam; i>0; i--) { res+=calcs[dp[i]]; } return res; } int main() { ll n, i, mi=0, ma=0, piv,pos; cin >> n; calcs.resize(n+1); calcs[0]=0; calcs[1]=0; for(i=2; i<=n; i++) { calcs[i]+=calcs[i-1]+(i-1); } vector<pair<ll,ll>>v(n); for(i=0; i<n; i++) { cin >> v[i].first >> v[i].second; tam=max(v[i].first,tam); } vector<ll> dp(tam+1,0); tamDP.resize(tam+1,0); for(i=0; i<n; i++) { dp[v[i].first]+=1; dp[v[i].first-v[i].second]-=1; tamDP[v[i].first]+=1; } ma=dp[tam]; for(i=tam-1; i>=0; i--) { dp[i]+=dp[i+1]; ma=max(ma,dp[i]); tamDP[i]+=tamDP[i+1]; } pos=ma; ma=LLONG_MAX; while(mi<=ma) { piv=(mi+ma)/2; if(can(dp,piv)) { ma=piv-1; pos=piv; } else { mi=piv+1; } } cout << calc(dp,pos); 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...