UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215177#2441. 物品STASISZHY601197ms13196kbC++112.1kb2024-11-26 22:20:172024-11-26 23:07:20

answer

// Problem: A. 物品
// Contest: undefined - NOIP2024训练赛 14
// URL: http://noi.ac/contest/1166/problem/2441
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
//#define int long long
#define fi first
#define se second
#define PII pair<int, int>

using namespace std;

const int N = 5e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;

int n, m, q, ans, sum;
int dp[N], cy[N];

struct node
{
	int fi, se, id;
}s[N];

// vector<int> e[N];

bool cmp(node a, node b) 
{
	if(a.fi == b.fi) return a.se < b.se;
	else return a.fi < b.fi;
}

inline bool check(int x)
{
	int l = lower_bound(cy + 1, cy + n + 1, x) - cy, res = 0;
	// cout << "l = " << l << '\n';
	priority_queue<int> pq;
	for(int i = l; i <= n; i ++)
	{
		if(s[i].se > m) continue;
		if(res + s[i].se <= m) pq.push(s[i].se), res += s[i].se;
		else
		{
			int now = pq.top(); 
			if(now < s[i].se) continue;
			else pq.pop(), pq.push(s[i].se), res -= now, res += s[i].se;
		}
	}
	return (int)pq.size() >= x;
}

inline void print(int x)
{
	int l = lower_bound(cy + 1, cy + n + 1, x) - cy, res = 0;
	// cout << "l = " << l << '\n';
	priority_queue<PII> pq;
	for(int i = l; i <= n; i ++)
	{
		if(s[i].se > m) continue;
		if(res + s[i].se <= m) pq.push({s[i].se, s[i].id}), res += s[i].se;
		else
		{
			int now = pq.top().fi; 
			if(now < s[i].se) continue;
			else pq.pop(), pq.push({s[i].se, s[i].id}), res -= now, res += s[i].se;
		}
	}
	cout << pq.size() << '\n';
	while(!pq.empty()) {cout << pq.top().se << ' '; pq.pop();}
	exit(0);
}

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) {cin >> s[i].fi >> s[i].se; s[i].id = i, cy[i] = s[i].fi;}
	sort(s + 1, s + n + 1, cmp); sort(cy + 1, cy + n + 1);
	int l = 1, r = n, res = 0;
	while(l <= r)
	{
		int mid = l + r >> 1;
		if(check(mid)) res = mid, l = mid + 1;
		else r = mid - 1;
	}
	cout << res << '\n';
	print(res);
	// cout << check(2) << '\n';
	return 0;
}

Details

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

Test #1:

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

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

result:

wrong answer Incorrect solution!

Test #2:

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

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: 1332kb

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 1253 845 29 1703 1295 1416 1254 357 235 1155 970 1206 754 772 1757 1549 931 1185 1830 184...

result:

points 1.0 Correct

Test #4:

score: 10
Accepted
time: 2ms
memory: 1340kb

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 1195 613 1179 1781 1515 ...

result:

points 1.0 Correct

Test #5:

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

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: 0
Wrong Answer
time: 121ms
memory: 5792kb

input:

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

output:

100168
100170
198556 197654 197131 195464 195249 193480 191373 186530 186422 184173 182523 181561 18...

result:

wrong answer Incorrect solution!

Test #7:

score: 0
Wrong Answer
time: 117ms
memory: 6220kb

input:

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

output:

98978
98984
199443 198870 182133 155018 147687 129435 112534 97391 83492 77724 68163 56912 43147 343...

result:

wrong answer Incorrect solution!

Test #8:

score: 10
Accepted
time: 257ms
memory: 11192kb

input:

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

output:

222615
222615
441057 429056 418696 417639 413098 412854 405073 395690 391697 391597 391348 390470 38...

result:

points 1.0 Correct

Test #9:

score: 0
Wrong Answer
time: 296ms
memory: 13196kb

input:

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

output:

254580
261156
488039 482557 477955 471337 469807 462170 461739 453629 446487 427458 422647 419485 41...

result:

wrong answer Incorrect solution!

Test #10:

score: 10
Accepted
time: 404ms
memory: 12964kb

input:

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

output:

231450
231450
58713 32892 27872 497113 485634 479860 457832 448595 436555 411767 407000 389661 38527...

result:

points 1.0 Correct