Submission #213054

# Submission time Handle Problem Language Result Execution time Memory
213054 2020-03-24T20:11:39 Z tatyam Sails (IOI07_sails) C++17
100 / 100
63 ms 5600 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
#define all(a) begin(a), end(a)
#define rep(a) for(int i = 0; i < a; i++)
#define each(i,a) for(auto&& i : a)
template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pii> a(n);
    each(i, a) cin >> i.first >> i.second;
    sort(all(a));
    multiset<int> X; // i 番目に大さい境界から i + 1 番目に大さい境界までが i である
    X.insert(0);
    each(i, a){
        auto [h, k] = i;
        X.insert(h);
        auto p = X.upper_bound(h - k), q = prev(p);
        int next = *q + *p - (h - k);
        if(q != X.begin()) X.erase(q);
        X.insert(next);
        X.erase(p);
    }
    ll ans = 0, cnt = 0;
    for(auto p = X.end(); p-- != X.begin(); cnt++) ans += cnt * *p;
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 20 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3448 KB Output is correct
2 Correct 43 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 5600 KB Output is correct
2 Correct 40 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 3468 KB Output is correct
2 Correct 50 ms 2456 KB Output is correct