ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#215231 | #2639. 省钱 | KXG | 30 | 191ms | 7492kb | C++11 | 1.6kb | 2024-11-27 19:09:48 | 2024-11-27 23:36:23 |
answer
#include <cstdio>
#include <queue>
using namespace std;
struct node {
long long q, w, x, id;
} nodes1[50010], nodes2[50010];
bool operator < (node a, node b) {
return a.x > b.x;
}
bool vis[50010];
priority_queue<node> pq1, pq2;
priority_queue<int> nowq;
int n, k;
long long s, ans;
int main() {
scanf("%d%d%lld", &n, &k, &s);
for (int i = 1; i <= n; i++) {
long long w, q;
scanf("%lld%lld", &w, &q);
nodes1[i].w = nodes2[i].w = nodes1[i].x = w;
nodes1[i].q = nodes2[i].q = nodes2[i].x = q;
nodes1[i].id = nodes2[i].id = i;
pq1.push(nodes1[i]);
pq2.push(nodes2[i]);
}
while (true) {
while (vis[pq1.top().id]) pq1.pop();
while (vis[pq2.top().id]) pq2.pop();
long long sub1 = pq1.top().x;
long long sub2 = pq2.top().x;
if (nowq.size() == k) {
if (nowq.empty()) {
sub2 += 1e18;
} else {
sub2 += nowq.top();
}
}
if (sub1 <= sub2) {
if (sub1 > s) {
break;
}
vis[pq1.top().id] = true;
s -= sub1;
ans++;
pq1.pop();
} else {
if (sub2 > s) {
break;
}
vis[pq2.top().id] = true;
s -= sub2;
ans++;
if (nowq.size() == k) {
nowq.pop();
nowq.push(pq2.top().w - pq2.top().q);
}
pq2.pop();
}
}
printf("%lld\n", ans);
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 14ms
memory: 7492kb
input:
50000 30828 852557364841 682084050 257603011 870868024 517458094 732267860 201407488 777566656 55879...
output:
17903
result:
ok single line: '17903'
Test #2:
score: 0
Wrong Answer
time: 27ms
memory: 7492kb
input:
50000 10508 8982273367520 34111224 12372852 549875017 525549262 357107918 219952140 644308048 222008...
output:
45004
result:
wrong answer 1st lines differ - expected: '37621', found: '45004'
Test #3:
score: 10
Accepted
time: 21ms
memory: 7492kb
input:
50000 23114 535861686266 359271294 298114231 605400720 491693949 755566780 539381575 155586610 92962...
output:
14723
result:
ok single line: '14723'
Test #4:
score: 0
Wrong Answer
time: 15ms
memory: 7492kb
input:
50000 13490 4616703243118 286358449 133228996 162995754 17235506 661390160 561824344 282751480 15433...
output:
35465
result:
wrong answer 1st lines differ - expected: '30961', found: '35465'
Test #5:
score: 0
Wrong Answer
time: 21ms
memory: 7492kb
input:
50000 26352 8630976119100 70133466 32927792 90392510 89764542 307782646 75889114 123168574 66039130 ...
output:
44599
result:
wrong answer 1st lines differ - expected: '42944', found: '44599'
Test #6:
score: 10
Accepted
time: 12ms
memory: 7488kb
input:
50000 11800 213255455323 405512104 311547645 122797690 35257030 782246460 533338866 416860264 504733...
output:
9869
result:
ok single line: '9869'
Test #7:
score: 0
Wrong Answer
time: 26ms
memory: 7488kb
input:
50000 19734 4267681411347 732638120 327229436 361949068 274173372 539440696 285784669 94445920 84513...
output:
34422
result:
wrong answer 1st lines differ - expected: '32498', found: '34422'
Test #8:
score: 0
Wrong Answer
time: 14ms
memory: 7488kb
input:
50000 254 18445304121 375481124 36148026 388507104 183081259 261838134 179691990 485282800 209534680...
output:
3285
result:
wrong answer 1st lines differ - expected: '1564', found: '3285'
Test #9:
score: 0
Wrong Answer
time: 19ms
memory: 7492kb
input:
50000 3260 4076050769242 210627773 8756794 68253913 5333287 812306900 176444281 561388618 94960450 6...
output:
33959
result:
wrong answer 1st lines differ - expected: '23173', found: '33959'
Test #10:
score: 0
Wrong Answer
time: 22ms
memory: 7492kb
input:
50000 44485 12129791734731 590854222 262410600 992399148 641692708 219274382 56485932 730651726 4088...
output:
49592
result:
wrong answer 1st lines differ - expected: '49537', found: '49592'