ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#215249 | #2639. 省钱 | wujiachen | 0 | 0ms | 0kb | C++ | 955b | 2024-11-27 20:24:57 | 2024-11-27 23:37:57 |
answer
#include<queue>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct pr{ int x,y; } x;
inline bool operator< (pr a,pr b){ return a.x>b.x; }
priority_queue<pr> q1,q2;
priority_queue<int,vector<int>,greater<int> > q;
int n,k,p[50010],c[50010],v[50010]; long long m;
int main(){
freopen("shopping.in","r",stdin);
freopen("shopping.out","w",stdout);
scanf("%d%d%lld",&n,&k,&m);
for(int i=n;i;--i) scanf("%d%d",p+i,c+i);
for(int i=k;i;--i) q.push(0);
for(int i=n;i;--i){
q1.push((pr){p[i],i});
q2.push((pr){c[i],i});
}
int ans=0;
for(;m>0 && ans<n;++ans){
for(;v[q1.top().y];q1.pop());
for(;v[q2.top().y];q2.pop());
if(q.top()+q2.top().x<q1.top().x){
x=q2.top();
m-=x.x+q.top();
if(m<0) break;
q.pop(); q.push(p[x.y]-c[x.y]);
v[x.y]=1; q2.pop();
} else {
x=q1.top();
m-=x.x;
if(m<0) break;
v[x.y]=1; q1.pop();
}
}
printf("%d\n",ans);
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Dangerous Syscalls
input:
50000 30828 852557364841 682084050 257603011 870868024 517458094 732267860 201407488 777566656 55879...
output:
result:
Test #2:
score: 0
Dangerous Syscalls
input:
50000 10508 8982273367520 34111224 12372852 549875017 525549262 357107918 219952140 644308048 222008...
output:
result:
Test #3:
score: 0
Dangerous Syscalls
input:
50000 23114 535861686266 359271294 298114231 605400720 491693949 755566780 539381575 155586610 92962...
output:
result:
Test #4:
score: 0
Dangerous Syscalls
input:
50000 13490 4616703243118 286358449 133228996 162995754 17235506 661390160 561824344 282751480 15433...
output:
result:
Test #5:
score: 0
Dangerous Syscalls
input:
50000 26352 8630976119100 70133466 32927792 90392510 89764542 307782646 75889114 123168574 66039130 ...
output:
result:
Test #6:
score: 0
Dangerous Syscalls
input:
50000 11800 213255455323 405512104 311547645 122797690 35257030 782246460 533338866 416860264 504733...
output:
result:
Test #7:
score: 0
Dangerous Syscalls
input:
50000 19734 4267681411347 732638120 327229436 361949068 274173372 539440696 285784669 94445920 84513...
output:
result:
Test #8:
score: 0
Dangerous Syscalls
input:
50000 254 18445304121 375481124 36148026 388507104 183081259 261838134 179691990 485282800 209534680...
output:
result:
Test #9:
score: 0
Dangerous Syscalls
input:
50000 3260 4076050769242 210627773 8756794 68253913 5333287 812306900 176444281 561388618 94960450 6...
output:
result:
Test #10:
score: 0
Dangerous Syscalls
input:
50000 44485 12129791734731 590854222 262410600 992399148 641692708 219274382 56485932 730651726 4088...