Submission #213054

#TimeUsernameProblemLanguageResultExecution timeMemory
213054tatyamSails (IOI07_sails)C++17
100 / 100
63 ms5600 KiB
#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 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...