Submission #912383

#TimeUsernameProblemLanguageResultExecution timeMemory
912383vjudge1Potatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
1030 ms98436 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n]; map <int, int> mp; map <int, int> mp1; map <int, int> mp2; map <int, int> mp3; int p = 0; int g = 0; int ok = 0; int okk = 0; long long cnt = 0; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (a[i] > 0) { mp2[okk] = a[i]; mp3[okk] = i; okk++; } if (b[i] > 0) { mp[ok] = b[i]; mp1[ok] = i; ok++; } } for (int j = 0; j < ok; j++) { for (int i = g; i < okk; i++) { if (mp[j] < mp2[i]) { cnt += mp[j]*abs(mp1[j]-mp3[i]); mp2[i] -= mp[j]; mp[j] = 0; break; } else { cnt += mp2[i]*abs(mp1[j]-mp3[i]); mp[j] -= mp2[i]; mp2[i] = 0; p++; if (mp[j] == mp2[i]) { break; } } } g += p; p = 0; } cout << cnt; }
#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...