QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#364211#7403. Subset SumieeWA 364ms4220kbC++23759b2024-03-24 13:02:202024-04-10 20:34:13

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 21:19:40]
  • hack成功,自动添加数据
  • (/hack/1150)
  • [2024-07-11 20:10:05]
  • hack成功,自动添加数据
  • (/hack/734)
  • [2024-05-30 11:41:28]
  • hack成功,自动添加数据
  • (/hack/643)
  • [2024-05-24 18:15:02]
  • hack成功,自动添加数据
  • (/hack/638)
  • [2024-05-04 13:41:40]
  • hack成功,自动添加数据
  • (/hack/612)
  • [2024-05-04 13:38:14]
  • hack成功,自动添加数据
  • (/hack/611)
  • [2024-04-10 20:34:13]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:WA
  • 用时:364ms
  • 内存:4220kb
  • [2024-04-10 20:33:52]
  • hack成功,自动添加数据
  • (/hack/593)
  • [2024-03-24 13:02:20]
  • 评测
  • 测评结果:100
  • 用时:178ms
  • 内存:4092kb
  • [2024-03-24 13:02:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
void solve() {
	int n, c;
	cin >> n >> c;
	vector<int> a(n);
	for (int &x : a) {
		cin >> x;
	}
	sort(a.begin(), a.end());
	int w = 0;
	for (int &x : a) {
		if (x <= c) {
			c -= x;
			w += x;
			x *= -1;
		}
	}
	static mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());
	constexpr int N = 4e5 + 5;
	bitset<N + N> f;
	f[N] = 1;
	shuffle(a.begin(), a.end(), eng);
	for (int x : a) {
		if (x > 0) f |= f << x;
		else f |= f >> -x;
	}
	c = min(c, N - 1);
	for (int i = N + c; ; i--) {
		if (f[i]) {
			cout << i - N + w << "\n";
			return;
		}
	}
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3980kb

input:

3
3 5
2 3 4
3 1
2 3 4
3 1000000000
2 3 4

output:

5
0
9

result:

ok 3 number(s): "5 0 9"

Test #2:

score: 0
Accepted
time: 181ms
memory: 3916kb

input:

100
63 133550
17234 638 8523 521 6421 19198 2712 17687 15811 11817 15849 16605 1708 12159 19831 3445 12529 5395 12206 6413 18377 12237 8080 4230 9407 15464 17360 12118 5457 18197 13144 12967 2675 4439 11235 4438 15498 678 6051 18356 18066 9068 1660 5640 6425 8106 16167 6316 6881 6068 13008 17228 98 ...

output:

133550
365866
455651
1072973
696051
849806
451783
329019
460849
243568
821923
519808
65293
722003
268371
12966
640372
91176
227453
478018
190943
1466983
672114
643379
417671
1304850
314401
88902
414529
252143
857248
22965
56336
1703029
967466
230626
125212
32989
236873
82417
387912
662080
946732
791...

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 184ms
memory: 4128kb

input:

100
106 50478
1352 1958 1292 1856 1152 1541 1553 1094 1001 1181 892 1346 624 1023 1228 886 917 306 998 1132 431 688 1583 1807 629 166 35 1983 1941 280 1074 1681 1840 202 637 653 1532 216 1069 1438 1633 1183 1405 70 589 1761 299 1383 720 438 1195 1451 1280 981 100 1916 871 1119 1120 1724 1408 1333 19...

output:

50478
45653
12264
4428
84946
43070
57632
58033
65049
765
39927
6818
58269
32740
90653
6870
27952
106994
64599
47143
6487
4797
189721
19401
34242
34705
124517
52619
49055
78061
174213
22618
22336
134278
1863
122954
116301
60398
19103
22939
96159
71213
135142
55080
48203
49758
11901
8306
2782
100089
5...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 180ms
memory: 3968kb

input:

100
63 4789
82 28 49 194 174 175 77 157 120 141 7 42 196 75 86 171 5 12 15 180 153 22 31 133 24 182 108 12 176 48 149 192 84 151 69 95 24 131 4 161 151 94 134 50 86 174 18 100 102 135 52 155 101 62 139 199 94 86 187 173 76 71 53
115 9099
23 90 33 151 120 7 98 102 103 48 83 32 81 118 89 123 61 183 1 ...

output:

4789
9099
1064
2379
5349
2408
15292
3114
544
6462
3934
3384
16266
1012
2023
1923
4953
171
15786
5492
9634
2681
15324
4916
7675
16888
7776
5870
1713
1962
5617
9778
241
3929
78
4290
2782
209
6269
704
502
5278
1836
5775
12042
1157
2781
483
6720
4264
3452
12534
11440
1248
14487
5741
9753
330
8638
5397
7...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 148ms
memory: 4192kb

input:

10
1160 4680552
14978 7415 15122 16423 6430 5558 10869 12737 9227 15677 5545 19975 3653 2233 15922 15454 15289 2184 14665 3904 1036 14654 7002 11707 6674 5956 1799 13712 631 16948 12515 14133 9210 17726 5623 12020 685 17447 4640 13450 9367 17317 79 8937 5010 18468 18696 19990 14765 12196 17123 4939 ...

output:

4680552
4282752
530079
95385
1585230
362527
2864670
4664186
4203737
763035

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 114ms
memory: 3988kb

input:

10
752 37012
853 1888 344 1574 750 1077 1123 1910 1083 1448 1366 1376 613 1530 45 435 522 810 758 1460 1418 65 1669 1804 1804 919 257 1286 1959 1018 1877 642 569 798 64 1509 804 1848 1749 967 604 178 1612 1683 1818 1755 847 922 636 1812 1454 1344 274 659 1115 1278 307 100 1087 1870 1238 1043 659 182...

output:

37012
98306
34284
601611
385732
155609
6564
408966
263837
187235

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 197ms
memory: 3952kb

input:

10
1141 104699
84 76 129 97 173 88 133 10 170 165 75 43 62 28 160 150 14 172 4 127 52 89 49 56 189 49 192 154 170 22 100 163 51 86 52 83 7 110 69 46 149 83 94 173 182 159 75 20 176 18 179 78 125 134 50 124 114 34 47 114 48 49 7 11 183 88 72 191 134 147 135 164 92 184 3 18 194 98 7 6 71 95 76 16 59 1...

output:

104699
49134
133546
44571
106611
26282
10257
28481
3142
44075

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 361ms
memory: 4220kb

input:

1
20000 133486437
9760 14402 14493 8153 8723 15946 5032 14575 11209 13193 5678 16284 17378 14678 10562 13910 15940 3275 14939 5755 4760 7782 17619 15914 4587 2536 1643 8103 3631 9273 7301 15996 12695 18786 4649 7667 9150 2097 8673 3773 193 11289 14204 11630 7648 911 15534 3646 15745 13134 10511 1152...

output:

133486437

result:

ok 1 number(s): "133486437"

Test #9:

score: 0
Accepted
time: 364ms
memory: 3968kb

input:

1
19998 12425665
1163 1478 876 333 1871 1515 175 322 244 1607 1822 1848 1524 1740 683 1627 715 1121 880 126 1933 592 710 1091 1774 728 1390 388 504 1003 1595 622 89 193 1302 417 1250 1332 121 1793 1321 386 85 472 376 1470 1980 1169 1484 704 1319 1071 1542 1120 929 340 1229 1182 841 826 1195 525 1413...

output:

12425665

result:

ok 1 number(s): "12425665"

Test #10:

score: 0
Accepted
time: 260ms
memory: 4024kb

input:

101
59 142633
11966 16383 15593 3668 15830 11706 13823 13451 5927 14112 5647 12867 13070 3458 5888 8230 1661 1667 15662 10736 17821 794 10284 18133 9031 915 16636 19513 18378 4366 6168 7926 9705 6335 877 6266 3226 5388 13627 998 4743 9298 11190 14448 16433 641 13832 13570 3528 603 14605 856 3924 607...

output:

142633
100389
75454
207625
323199
752180
183578
727450
366962
531604
223686
407596
46087
501868
765383
207818
235484
132311
123265
685660
555
116111
269446
296167
255307
0
123156
300520
384150
341568
25155
251433
436722
12114
37914
240792
458220
416297
475485
86791
650154
374621
73377
22742
115929
2...

result:

ok 101 numbers

Extra Test:

score: -3
Extra Test Failed : Wrong Answer on 5
time: 362ms
memory: 3944kb

input:

40
500 5000000
19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 199...

output:

5000000
5000000
5000000
4999988
5000000
5000000
5000000
4999988
5000000
4999986
4999994
5000000
5000000
5000000
5000000
4999997
4999999
4999998
4999995
5000000
5000000
4999994
5000000
4999994
4999997
5000000
4999997
5000000
4999993
5000000
5000000
5000000
5000000
4999995
5000000
5000000
4999997
5000...

result:

wrong answer 4th numbers differ - expected: '5000000', found: '4999988'