Submission #1128576

#TimeUsernameProblemLanguageResultExecution timeMemory
1128576AverageAmogusEnjoyerSails (IOI07_sails)C++17
70 / 100
1095 ms1772 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> bool cmin(T &i, T j) { return i > j ? i=j,true:false; } template<class T> bool cmax(T &i, T j) { return i < j ? i=j,true:false; } mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> ui(0, 1 << 30); int rng() { return ui(mrand); } const int N=100100; int n; int h[N],k[N]; int placed[N]; int new_placed[N]; int order[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i=0;i<n;i++) cin >> h[i] >> k[i]; iota(order,order+n,0); sort(order,order+n,[&](int i,int j) { return h[i] < h[j]; }); // placed[0] += diff // int lh = 0; for (int t=0;t<n;t++) { int i = order[t]; int diff = h[i] - lh; lh = h[i]; placed[0] += diff; int j = 0; new_placed[0] = placed[0]; for (;k[i]>0;j++) { int now = min(k[i],placed[j]); new_placed[j + 1] = placed[j + 1] + now; k[i] -= now; new_placed[j] -= now; } for (int z=0;z<=j;z++) placed[z] = new_placed[z]; // for (int z=0;z<=10;z++) // cout << placed[z] << " "; // cout << endl; } ll ans = 0; for (int i=0;i<N;i++) { ans += 1LL * i * (i - 1) / 2 * placed[i]; } cout << ans << 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...