UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215110#2441. 物品N0995ms21984kbC++112.2kb2024-11-26 19:13:382024-11-26 23:01:21

answer

//
//  na 2441.cpp
//  Competitive Programming
//
//  Created by m2 on 2024/11/26.
//

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 5e5 + 5;
int n, C, inv, ansm, ansval;
inline int rd(){
    int v = 0; char r = getchar();
    while(r - 48 >= 10u)
        r = getchar();
    do{
        v = (v << 3) + (v << 1) + (r ^ 48);
        r = getchar();
    }while(r - 48 < 10u);
    return v;
}
void pr(int x){
    if(x < 10)
        putchar(x ^ 48);
    else{
        pr(x / 10);
        putchar((x % 10) ^ 48);
    }
}
struct Pkg{
    int a, w, id;
    inline void read(int id){ a = rd(); w = rd(); this->id = id; }
    inline bool operator < (const Pkg &other) const{ return w < other.w; }
}ps[maxn];
struct Cmpa{
    inline bool operator() (const Pkg &a, const Pkg &b){ return a.a < b.a; }
};
inline bool cmpa(const Pkg &a, const Pkg &b){ return a.a < b.a; }
priority_queue<Pkg, vector<Pkg>, Cmpa> pack;
priority_queue<Pkg> rest;
vector<int> ans;
int main(){
    cin.tie(0)->sync_with_stdio(false);
    n = rd(); C = rd();
    for(int i = 0; i < n; ++i){
        ps[i].read(i + 1);
        rest.push(ps[i]);
    }
    for(int i = 1; i <= n; ++i){
        while(!pack.empty() && pack.top().a < i){
            inv -= pack.top().w;
            pack.pop();
        }
        while(pack.size() < i && !rest.empty() && inv + rest.top().w <= C){
            if(rest.top().a < i){
                rest.pop();
                continue;
            }
            inv += rest.top().w;
            pack.push(rest.top());
            rest.pop();
        }
        if(pack.size() > ansval){
            ansval = int(pack.size());
            ansm = i;
        }
    }
    pr(ansval); putchar('\n');
    sort(ps, ps + n, cmpa);
    int p = 0;
    while(ps[p].a < ansm)
        ++p;
    sort(ps + p, ps + n);
    inv = 0;
    while(p < n && inv + ps[p].w <= C){
        inv += ps[p].w;
        ans.push_back(ps[p].id);
        ++p;
    }
    pr(int(ans.size())); putchar('\n');
    for(int i: ans){
        pr(i); putchar(' ');
    }
    putchar('\n');
    fflush(stdout);
    return 0;
}

详细

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

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 1228kb

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:

10
7
9 6 10 12 18 4 3 

result:

wrong answer Wrong answer!

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 1224kb

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:

9
12
4 12 14 1 13 2 16 18 20 19 11 6 

result:

wrong answer Wrong answer!

Test #3:

score: 0
Wrong Answer
time: 1ms
memory: 1312kb

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:

1212
707
909 1341 231 335 1327 1259 873 892 1671 1070 1872 452 339 501 258 1067 1812 164 1483 1032 1...

result:

wrong answer Wrong answer!

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 1316kb

input:

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

output:

1273
703
53 174 195 1092 1807 517 789 1823 1014 423 991 1060 1800 350 769 1484 1428 704 795 492 1229...

result:

wrong answer Wrong answer!

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 1312kb

input:

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

output:

1254
762
725 67 1669 1837 1146 694 223 1735 1651 1228 358 1005 811 1180 1094 1150 1008 1158 688 925 ...

result:

wrong answer Wrong answer!

Test #6:

score: 0
Wrong Answer
time: 85ms
memory: 8880kb

input:

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

output:

126628
73804
17733 18542 99550 66108 35776 45559 66218 128891 163690 46651 168721 94405 35516 156715...

result:

wrong answer Wrong answer!

Test #7:

score: 0
Wrong Answer
time: 100ms
memory: 8880kb

input:

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

output:

125813
74997
130989 74944 134505 23020 162221 198760 42096 30257 26517 160938 187451 34552 154229 19...

result:

wrong answer Wrong answer!

Test #8:

score: 0
Wrong Answer
time: 211ms
memory: 20664kb

input:

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

output:

281555
163515
410574 278320 413312 360643 264334 441315 226535 136240 417327 428445 25162 185812 168...

result:

wrong answer Wrong answer!

Test #9:

score: 0
Wrong Answer
time: 320ms
memory: 21984kb

input:

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

output:

318939
162509
299782 269073 53258 96411 258580 147942 459423 418440 421364 375045 70097 403650 29066...

result:

wrong answer Wrong answer!

Test #10:

score: 0
Wrong Answer
time: 276ms
memory: 17764kb

input:

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

output:

114101
277535
481176 162184 172853 129939 473585 69113 135869 142744 60258 354871 55924 428396 35075...

result:

wrong answer Wrong answer!