UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215138#2441. 物品nodgd100998ms10060kbC++111.2kb2024-11-26 20:00:392024-11-26 23:03:37

answer

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 500000 + 5;

int N, C;
struct Node {
    int a, w, i;
    bool operator < (const Node &t) const {
        return w < t.w;
    }
} a[MAX_N];
bool cmp(const Node &u, const Node &v) {
    return u.a < v.a;
}
priority_queue<Node> pq;

int main() {
    scanf("%d%d", &N, &C);
    for (int i = 1; i <= N; i ++) {
        scanf("%d%d", &a[i].a, &a[i].w);
        a[i].i = i;
    }
    sort(a + 1, a + 1 + N, cmp);
    long long w = 0, ans = 0;
    for (int i = N; i >= 1; i --) {
        w += a[i].w;
        pq.push(a[i]);
        while (pq.size() > a[i].a || w > C) {
            w -= pq.top().w;
            pq.pop();
        }
        ans = max(ans, (long long)pq.size());
    }
    for (; pq.size(); pq.pop());
    printf("%d\n", ans);
    printf("%d\n", ans);
    w = 0;
    for (int i = N; i >= 1; i --) {
        w += a[i].w;
        pq.push(a[i]);
        while (pq.size() > a[i].a || w > C) {
            w -= pq.top().w;
            pq.pop();
        }
        if (ans == pq.size()) {
            for (; pq.size(); pq.pop()) {
                printf("%d ", pq.top().i);
            }
            break;
        }
    }
    printf("\n");
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1244kb

input:

18 1024
8 3
8 1
16 9
17 6
2 5
12 3
1 7
7 9
17 1
14 3
2 7
17 5
2 3
2 5
2 10
8 3
2 3
17 5

output:

8
8
3 4 18 12 10 1 6 9 

result:

points 1.0 Correct

Test #2:

score: 10
Accepted
time: 0ms
memory: 1248kb

input:

20 79841
15 4337
9 6289
7 9927
12 1468
7 9390
12 9228
7 5646
8 3438
3 1614
3 7048
10 8840
15 2349
16...

output:

10
10
17 6 11 19 20 13 1 14 12 4 

result:

points 1.0 Correct

Test #3:

score: 10
Accepted
time: 0ms
memory: 1292kb

input:

1888 987654
1082 243
1341 309
1524 959
324 593
894 952
1428 587
1367 91
1669 683
616 866
958 791
172...

output:

949
949
65 845 1253 29 1295 1703 1254 1416 235 357 1155 970 1206 754 772 1757 1549 931 1185 1830 184...

result:

points 1.0 Correct

Test #4:

score: 10
Accepted
time: 0ms
memory: 1292kb

input:

1999 12000000
1112 2799
524 6890
686 6713
1803 4478
940 4341
1391 8972
953 592
454 7711
524 8224
127...

output:

978
978
1745 845 1503 1633 826 246 259 399 1675 1987 1114 1196 215 1288 265 613 1195 1179 1781 1515 ...

result:

points 1.0 Correct

Test #5:

score: 10
Accepted
time: 1ms
memory: 1288kb

input:

2000 9788123
296 3976
154 3441
78 9146
1443 6444
1799 2843
1482 6843
1526 3159
1956 9324
1442 1001
5...

output:

997
997
633 1385 1135 462 284 1955 639 558 1531 1028 955 1418 771 161 252 1983 417 1901 953 55 458 6...

result:

points 1.0 Correct

Test #6:

score: 10
Accepted
time: 103ms
memory: 5108kb

input:

200000 87654321
33240 503
90721 868
64272 858
170928 616
92246 213
50575 59
148252 954
87639 739
328...

output:

100168
100168
198556 48928 57165 19984 48406 77961 72156 195249 44110 65993 108165 41641 177762 4308...

result:

points 1.0 Correct

Test #7:

score: 10
Accepted
time: 105ms
memory: 5108kb

input:

200000 987654321
199051 7573
6332 5631
35615 9816
185684 9227
198894 8029
185684 2173
54203 2887
107...

output:

98978
98978
77724 198870 56912 199443 155018 129435 83492 147687 43147 112534 68163 34319 97391 1821...

result:

points 1.0 Correct

Test #8:

score: 10
Accepted
time: 235ms
memory: 9412kb

input:

444444 998244353
243276 2272
436596 1761
70822 1547
263965 942
280972 2658
87160 421
268504 2945
103...

output:

222615
222615
331537 322350 55721 330793 342779 341837 279341 395690 405073 391697 148651 371772 206...

result:

points 1.0 Correct

Test #9:

score: 10
Accepted
time: 270ms
memory: 10060kb

input:

500000 999999999
131412 807
486292 804
462352 1139
52896 196
426775 1655
18059 2099
224414 1308
2851...

output:

254580
254580
273615 179449 75490 36753 298631 358922 36219 77989 232425 408807 225536 354247 13374 ...

result:

points 1.0 Correct

Test #10:

score: 10
Accepted
time: 284ms
memory: 10060kb

input:

500000 1000000000
42362 5090
327916 7618
221602 679
295161 1419
69703 4221
108614 6788
210597 6940
2...

output:

231450
231450
127673 109576 290868 422302 188112 290074 485634 30967 407000 457832 298653 411767 824...

result:

points 1.0 Correct