UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215114#2441. 物品meixuan1001424ms9000kbC++11899b2024-11-26 19:27:252024-11-26 23:01:50

answer

#include<bits/stdc++.h>
using namespace std;
struct node{
	int w,a,id;
}t[1000001];
bool cmp(node a,node b){
	return a.w<b.w;
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
int main(){
	int n,c;
	cin >>n>>c;
	for(int i=1;i<=n;i++){
		cin >>t[i].a>>t[i].w;
		t[i].id=i;
	}
	sort(t+1,t+n+1,cmp);
	int now=0,tot=1,m=0,ans=0;
	for(int i=1;i<=n;i++){
		while((!q.empty())&&(q.top().first<i))m--,now-=q.top().second,q.pop();
		for(;tot<=n;tot++){
			if(m+1>i)break;
			if(t[tot].a<i)continue;
			if(now+t[tot].w>c)break;
			now+=t[tot].w;
			m++;
			q.push(make_pair(t[tot].a,t[tot].w));
		}
	//	cout <<"i:  "<<i<<' '<<now<<' '<<m<<' '<<tot<<endl;
	//	if(!q.empty())cout <<q.top().first<<endl;
		ans=max(ans,m);
	}
	cout <<ans<<endl<<ans<<endl;
	int j=1;
	for(int i=1;i<=n;i++){
		if(t[i].a>=ans&&j<=ans)cout <<t[i].id<<' ',j++;
	}
}

详细

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

Test #1:

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

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

result:

points 1.0 Correct

Test #2:

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

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

result:

points 1.0 Correct

Test #3:

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

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
909 1341 231 1327 335 1259 892 873 1671 1070 1872 452 339 501 258 1027 793 1067 1740 665 851...

result:

points 1.0 Correct

Test #4:

score: 10
Accepted
time: 2ms
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
53 174 195 1092 1807 517 789 1823 1014 991 423 1060 1800 350 769 1484 1428 1739 704 795 492 ...

result:

points 1.0 Correct

Test #5:

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

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
725 67 1669 1837 1146 694 38 223 1735 1651 1228 358 1005 811 1395 1180 1094 1150 1697 1008 1...

result:

points 1.0 Correct

Test #6:

score: 10
Accepted
time: 153ms
memory: 4432kb

input:

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

output:

100168
100168
73693 2146 34184 78313 184317 86718 9998 92978 67876 165591 151230 141220 61386 154752...

result:

points 1.0 Correct

Test #7:

score: 10
Accepted
time: 157ms
memory: 4436kb

input:

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

output:

98978
98978
42096 30257 96841 74944 23020 162221 198760 134505 130989 114816 197 26517 160938 59838 ...

result:

points 1.0 Correct

Test #8:

score: 10
Accepted
time: 338ms
memory: 8344kb

input:

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

output:

222615
222615
317639 191215 80924 243074 69477 223986 107338 169919 378635 278320 327893 422528 2076...

result:

points 1.0 Correct

Test #9:

score: 10
Accepted
time: 394ms
memory: 9000kb

input:

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

output:

254580
254580
357419 85619 58426 29508 162688 167478 184404 152285 111786 355073 229362 155356 34846...

result:

points 1.0 Correct

Test #10:

score: 10
Accepted
time: 379ms
memory: 8996kb

input:

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

output:

231450
231450
172777 55924 11704 458550 129939 117246 162184 154947 146074 196948 60258 428396 16974...

result:

points 1.0 Correct