Submission #242677

#TimeUsernameProblemLanguageResultExecution timeMemory
242677WhaleVomitPotatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
277 ms25064 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define MOO(i, a, b) for(int i=a; i<b; i++) #define M00(i, a) for(int i=0; i<a; i++) #define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--) #define M00d(i,a) for(int i = (a)-1; i>=0; i--) #define FAST ios::sync_with_stdio(0); cin.tie(0); #define finish(x) return cout << x << '\n', 0; #define dbg(x) cerr << ">>> " << #x << " = " << x << "\n"; #define _ << " _ " << typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int,int> pi; typedef pair<ld,ld> pd; typedef complex<ld> cd; int main() { FAST int n; cin >> n; vector<ll> diff(n); M00(i, n) { ll a, b; cin >> a >> b; diff[i] = a-b; } vector<ll> d(n); d[0] = diff[0]; MOO(i, 1, n) d[i] = d[i-1] + diff[i]; ll ans = 0; M00(i, n) ans += abs(d[i]); priority_queue<ll> pq; M00(i, n) { pq.push(d[i]); pq.push(d[i]); pq.pop(); } vector<ll> changes; while(!pq.empty()) { changes.pb(pq.top()); pq.pop(); } reverse(all(changes)); ll curslope = sz(changes); ll last = 0; M00(i, sz(changes)) { if(changes[i] < 0) { curslope--; continue; } if(changes[i] > d[n-1]) break; ans -= curslope * (changes[i] - last); last = changes[i]; curslope--; } finish(ans); }
#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...