제출 #1129737

#제출 시각아이디문제언어결과실행 시간메모리
1129737Alihan_8Sails (IOI07_sails)C++20
0 / 100
1096 ms2240 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' #define size(x) (int)(x).size() #define int long long typedef pair <int,int> pii; using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } const int N = 1e5 + 5; int cnt[N + 5]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for ( int i = 0; i < n; i++ ){ int h, k; cin >> h >> k; cnt[h - k + 1] += 1; cnt[h + 1] -= 1; } for ( int i = 1; i < N; i++ ) cnt[i] += cnt[i - 1]; priority_queue <int> q; for ( int i = 1; i < N; i++ ){ while ( size(q) && -q.top() + 2 < cnt[i] ){ int u = -q.top(); q.pop(); cnt[i] -= 1, u += 1; q.push(-u); } q.push(-cnt[i]); } int ans = 0; while ( size(q) ){ int x = -q.top(); q.pop(); ans += x * (x - 1) / 2; } cout << ans; cout << '\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...