Submission #00290


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
int n, d;
cin >> n >> d;
if (n == 0 && d == 0) {
return(0);
}
long long ans = 0;
long long a[n], b[n];
long long x[n];
priority_queue<pair<long long, int>> pq;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
x[i] = a[i];
pq.push({a[i], i});
}
set<int> s;
for (int i = 0; i < d; i++) {
long long num;
int pos;
while (1) {
num = pq.top().first;
pos = pq.top().second;
pq.pop();
if (x[pos] - b[pos] >= 0) {
break;
}
}
ans += num;
x[pos] -= b[pos];
s.insert(pos);
pq.push({x[pos], pos});
for (auto itr = s.begin(); itr != s.end(); itr++) {
if (*itr != pos) {
x[*itr] = min(x[*itr] + b[*itr], a[*itr]);
pq.push({x[*itr], *itr});
if (x[*itr] == a[*itr]) {
s.erase(*itr);
}
}
}
}
cout << ans << "\n";
}
return(0);
}

ステータス

項目 データ
問題 0010 - ゲーム
ユーザー名 woody_1227
投稿日時 2024-03-29 14:58:46
言語 C++17
状態 Time Limit Exceeded
得点 0
ソースコード長 1373 Byte
最大実行時間 8000 ms
最大メモリ使用量 648 KB

セット

セット 得点 Cases
1 ALL 0 / 40 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
C1 TLE 8000 ms 476 KB
1
C2 TLE 8000 ms 448 KB
1
C3 TLE 8000 ms 548 KB
1
C4 TLE 8000 ms 648 KB
1