UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215121#2441. 物品stawalr100765ms14916kbC++111.2kb2024-11-26 19:35:232024-11-26 23:02:13

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mn=5e5+5;
struct item
{
    int a,w,id;
}a[mn];
int n,c;
int b[mn],tp;
bool cmp(item x,item y)
{
    return x.w<y.w;
}
bool check(int x)
{
    int left=c,cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i].a<x)continue;
        cnt++;
        left-=a[i].w;
        if(left<0)return 0;
        if(cnt==x)return 1;
    }
    return (cnt==x);
}
signed main()
{
    scanf("%lld%lld",&n,&c);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&a[i].a,&a[i].w);
        a[i].id=i;
    }
    sort(a+1,a+n+1,cmp);
    int l=1,r=n,ans=-1;
    while(l<=r)
    {
        int mid=(((long long)l+(long long)r)>>1);
        if(check(mid))
        {
            ans=mid;
            l=mid+1;
        }
        else
        {
            r=mid-1;
        }
    }
    printf("%lld\n%lld\n",ans,ans);
    for(int i=1;i<=n;i++)
    {
        if(a[i].a<ans)continue;
        b[++tp]=a[i].id;
        if(ans==tp)break;
    }
    sort(b+1,b+tp+1);
    for(int i=1;i<=tp;i++)
    {
        printf("%lld ",b[i]);
    }
    printf("\n");
    return 0;
}

详细

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

Test #1:

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

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
1 2 6 9 10 12 16 18 

result:

points 1.0 Correct

Test #2:

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

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
1 4 6 11 12 13 14 17 19 20 

result:

points 1.0 Correct

Test #3:

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

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
1 2 3 6 7 8 10 11 12 13 14 16 22 23 25 27 28 29 30 34 35 36 39 40 41 42 44 47 48 49 50 51 55...

result:

points 1.0 Correct

Test #4:

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

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
1 4 6 11 12 14 15 18 19 20 21 24 25 28 30 33 34 37 38 41 45 46 48 50 52 53 56 58 59 66 68 70...

result:

points 1.0 Correct

Test #5:

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

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
4 5 6 7 8 9 11 18 20 26 28 29 30 31 32 34 36 38 41 42 44 45 48 51 53 54 55 56 57 60 61 63 65...

result:

points 1.0 Correct

Test #6:

score: 10
Accepted
time: 77ms
memory: 6680kb

input:

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

output:

100168
100168
4 7 12 16 17 18 20 21 26 27 28 29 30 32 34 37 38 43 44 47 48 51 54 55 57 60 62 63 66 6...

result:

points 1.0 Correct

Test #7:

score: 10
Accepted
time: 85ms
memory: 6668kb

input:

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

output:

98978
98978
1 4 5 6 8 11 12 13 16 17 18 19 20 22 27 28 31 32 33 34 35 37 40 46 51 53 54 57 60 61 62 ...

result:

points 1.0 Correct

Test #8:

score: 10
Accepted
time: 187ms
memory: 13364kb

input:

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

output:

222615
222615
1 2 4 5 7 10 12 17 19 20 23 24 25 26 29 30 33 34 36 37 40 42 44 45 48 50 56 59 60 61 6...

result:

points 1.0 Correct

Test #9:

score: 10
Accepted
time: 208ms
memory: 14916kb

input:

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

output:

254580
254580
2 3 5 8 9 10 13 14 15 17 18 20 24 26 27 28 29 34 35 37 41 42 44 45 48 56 57 58 59 61 6...

result:

points 1.0 Correct

Test #10:

score: 10
Accepted
time: 207ms
memory: 14736kb

input:

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

output:

231450
231450
2 4 12 14 16 18 19 24 27 33 37 42 43 47 49 52 53 55 56 59 60 62 67 68 69 74 75 77 78 7...

result:

points 1.0 Correct