ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187523 | #3368. 打怪闯关 | 2951154480 | 100 | 16ms | 2476kb | C++11 | 605b | 2023-10-02 10:18:15 | 2023-10-02 12:37:52 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>p;
int n,hp,a[100010],b[100010];
priority_queue<p>q;
int main()
{
int ans=0;
scanf("%d%d",&n,&hp);
for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
for(int i=1;i<=n;i++){
if(hp>a[i]){
hp=hp-a[i]+b[i];
q.push({a[i],b[i]});
}
else{
ans++;
int k=a[i];
if(q.empty()) hp+=b[i];
else if(q.top().first>k||q.top().first==k&&q.top().second>b[i]){
hp+=q.top().first;
q.pop();
hp=hp-a[i]+b[i];
q.push({a[i],b[i]});
}
else hp+=b[i];
}
}
printf("%d",ans);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 1232kb
input:
2 5 5 3 3 4
output:
1
result:
ok single line: '1'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1228kb
input:
8 26 38 3 28 15 16 3 44 29 27 16 30 26 20 11 33 19
output:
3
result:
ok single line: '3'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1232kb
input:
10 26 22 10 29 25 18 13 43 10 37 4 23 11 16 6 46 35 39 10 26 20
output:
4
result:
ok single line: '4'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
991 3081 2149 0 9730 0 1890 0 6659 0 9526 0 2240 0 3513 0 720 0 7828 0 7676 0 9905 0 9583 0 9400 0 2...
output:
970
result:
ok single line: '970'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
1000 9221 6895 0 9009 0 2330 0 6982 0 2952 0 2853 0 7734 0 7242 0 9937 0 4914 0 8390 0 6394 0 2513 0...
output:
950
result:
ok single line: '950'
Test #6:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
995 770 7448 0 5184 0 8577 0 8793 0 970 0 362 0 1955 0 660 0 4750 0 2151 0 4171 0 3206 0 5627 0 3856...
output:
985
result:
ok single line: '985'
Test #7:
score: 10
Accepted
time: 0ms
memory: 1260kb
input:
993 5422 4898 454 9872 3356 9017 379 1820 197 8988 914 575 1188 6176 2226 9886 1576 1051 3190 9389 2...
output:
444
result:
ok single line: '444'
Test #8:
score: 10
Accepted
time: 0ms
memory: 1260kb
input:
991 1563 5451 2619 3343 1298 9457 651 3631 868 9710 1991 3893 1406 4590 478 9112 621 3159 663 6627 7...
output:
477
result:
ok single line: '477'
Test #9:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
993 407 197 784 8030 2340 2600 2629 6658 173 7729 3069 1402 3040 8811 1501 2530 1310 7972 1275 6568 ...
output:
483
result:
ok single line: '483'
Test #10:
score: 10
Accepted
time: 15ms
memory: 2476kb
input:
99436 6518 4071 628 3967 598 9513 2785 2337 534 3076 1048 5703 458 5984 489 3387 542 4054 4140 5 963...
output:
46265
result:
ok single line: '46265'
Extra Test:
score: 0
Extra Test Passed