Submission #756071

#TimeUsernameProblemLanguageResultExecution timeMemory
756071SanguineChameleonSails (IOI07_sails)C++17
50 / 100
1080 ms1364 KiB
#include <bits/stdc++.h> using namespace std; void just_do_it(); int main() { #ifdef KAMIRULEZ freopen("kamirulez.inp", "r", stdin); freopen("kamirulez.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); just_do_it(); return 0; } const int maxn = 1e5 + 20; pair<int, int> a[maxn]; vector<pair<int, int>> q; void add(int val, int cnt) { if (!cnt) { return; } if (!q.empty() && q.back().first == val) { q.back().second += cnt; } else { q.emplace_back(val, cnt); } } void just_do_it() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { add(0, a[i].first - a[i - 1].first); vector<pair<int, int>> nxt; while (a[i].second) { if (q.back().second >= a[i].second) { nxt.emplace_back(q.back().first, q.back().second - a[i].second); nxt.emplace_back(q.back().first + 1, a[i].second); a[i].second = 0; } else { nxt.emplace_back(q.back().first + 1, q.back().second); a[i].second -= q.back().second; } q.pop_back(); } reverse(nxt.begin(), nxt.end()); for (auto p: nxt) { add(p.first, p.second); } } long long res = 0; for (auto p: q) { res += 1LL * p.first * (p.first - 1) / 2 * p.second; } 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...