이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int TIME = clock();
#define file \
freopen("in.txt" , "r" , stdin); \
freopen("out.txt" , "w" , stdout);
typedef long long ll;
void test_case () {
int n , mx = 0;
cin >> n;
vector<array<int , 2>> a(n);
for (int i = 0;i < n;i ++) {
cin >> a[i][0] >> a[i][1];
mx = max(mx , a[i][0]);
}
set<pair<int , int>> s;
for (int i = 0;i < mx;i ++) {
s.insert({0 , i});
}
ll res = 0;
for (int i = n - 1;i >= 0;i --) {
vector<pair<int , int>> _s;
while (a[i][1] --) {
assert((int)s.size() > 0);
auto it = *s.begin();
s.erase(s.begin());
if (it.second >= a[i][0]) {
a[i][1] ++;
_s.push_back(it);
continue;
}
res += it.first;
_s.push_back({it.first + 1 , it.second});
}
for (int j = 0;j < (int)_s.size();j ++) {
s.insert(_s[j]);
}
}
cout << res << "\n";
}
int32_t main () {
//// file
int t = 1;
// cin >> t;
while (t --) {
test_case();
}
cerr << "\nTime elapsed: " << (clock() - TIME) * 1000.0 / CLOCKS_PER_SEC << " ms\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |