Submission #502868

# Submission time Handle Problem Language Result Execution time Memory
502868 2022-01-06T16:26:18 Z tabr Sails (IOI07_sails) C++17
50 / 100
1000 ms 2356 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    const int m = (int) 1e5 + 10;
    vector<int> a(m);
    for (int i = 0; i < n; i++) {
        int h, k;
        cin >> h >> k;
        a[h]--;
        a[h - k]++;
    }
    for (int i = 0; i < m - 1; i++) {
        a[i + 1] += a[i];
    }
    priority_queue<int> pq;
    pq.emplace(0);
    for (int i = m - 1; i >= 0; i--) {
        while (pq.top() - 1 >= a[i] + 1) {
            int b = pq.top();
            a[i]++;
            b--;
            pq.pop();
            pq.emplace(b);
        }
        pq.emplace(a[i]);
    }
    long long ans = 0;
    while (!pq.empty()) {
        int b = pq.top();
        pq.pop();
        ans += 1LL * b * (b - 1) / 2;
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1360 KB Output is correct
2 Correct 3 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1360 KB Output is correct
2 Correct 3 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1360 KB Output is correct
2 Correct 4 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1360 KB Output is correct
2 Correct 7 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1352 KB Output is correct
2 Correct 84 ms 1348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 1608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 1908 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 1904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 2356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 2316 KB Time limit exceeded
2 Halted 0 ms 0 KB -