Source Code
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int n, a1[1000000], a2[1000000];
pair<int, int> a[1000000];
int main(){
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	long long s, ans = 0;
	cin >> n >> s;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].first;
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].second;
	}
	for (int i = 0; i < n; ++i)
	{

		a1[i] = (a[i].second - a[i].first);
	}
	sort(a1, a1 + n);

	for (int i = n- 1; i >= 0; --i)
	{
		// cout  << s << endl;
		s += a1[i];
		ans++;
		if (s <= 0)
		{
			break;
		}
	}
	cout << ans;



	return 0;

}
Copy
Wheatly's portals - Easy version microwave6
GNU G++17
332 ms
12.4 MB
Accepted
Test Case #1
3 ms
256 KB
Accepted
Input
6 6
3 5 8 22 36 21
6 5 6 12 2 1
Output
4
Judge Output
4
Checker Message
single line: '4'
Test Case #2
2 ms
508 KB
Accepted
Input
4 12
20 20 20 20
0 0 0 0
Output
1
Judge Output
1
Checker Message
single line: '1'
Test Case #3
3 ms
592 KB
Accepted
Input
402 19498
74168 71296 34906 56808 72291 49200 33593 65174 82490 68740 84749 96040 62517 53704 8006 24390 83501 56459 33847 34319 21614 83391 47366 40581 56019 59197 44005 52604 91193 32767 67433 48511 28551 65556 10301 54439 55206 53606 66528 25125 ...
Output
402
Judge Output
402
Checker Message
single line: '402'
Test Case #4
3 ms
596 KB
Accepted
Input
312 3637
19547 27526 902 83342 58372 43518 25892 3286 37908 68843 99698 29266 87809 84368 54200 13154 15556 76583 7251 74707 66433 76863 58659 2903 29416 21119 43595 22915 11647 33958 29659 38940 24798 70395 4187 21685 88996 74589 40364 90382 72429 ...
Output
312
Judge Output
312
Checker Message
single line: '312'
Test Case #5
3 ms
792 KB
Accepted
Input
476 296
24136 61116 21668 78538 2999 95547 6551 27210 75922 88098 48821 29221 72468 12083 16510 22735 77433 72214 93170 64228 30138 92440 6291 60186 61637 78596 25990 43365 67537 28348 45224 83772 91814 94041 43326 616 37204 62019 83691 32817 88228 ...
Output
467
Judge Output
467
Checker Message
single line: '467'
Test Case #6
2 ms
660 KB
Accepted
Input
174 22145
87705 1998 53688 23126 96744 16648 94095 56823 61397 27576 15203 7522 26616 86298 36620 48472 11039 24592 77501 36026 46025 63001 84642 38473 76354 53054 1557 64219 19473 79748 71677 80945 99782 8567 23363 23328 32641 9122 8470 15515 564 7...
Output
174
Judge Output
174
Checker Message
single line: '174'
Test Case #7
2 ms
728 KB
Accepted
Input
12 93977
53508 43629 2897 9670 28357 77355 9500 49230 59709 45656 9210 36268
2311 12743 82209 97697 10379 69909 44436 97625 48249 98928 14945 18749
Output
12
Judge Output
12
Checker Message
single line: '12'
Test Case #8
5 ms
836 KB
Accepted
Input
4003 62960
20540 84343 36530 14274 84326 70723 77714 95674 63903 505 10770 40107 12344 25765 74404 35822 19746 47171 82202 47388 25647 49504 10248 88622 54466 17526 11521 54594 9857 58706 56889 85439 64654 28366 68491 87748 10508 52606 79713 20589 4...
Output
4003
Judge Output
4003
Checker Message
single line: '4003'
Test Case #9
5 ms
704 KB
Accepted
Input
5207 87385
6011 57275 84029 78263 96864 3450 50805 59057 59724 51009 52378 30143 26727 27218 34167 88001 7402 95019 55252 8170 53573 52311 63661 21052 89873 822 28614 65373 66854 1053 49561 88255 50054 45108 4215 67243 48076 21356 29849 46039 16292 ...
Output
5175
Judge Output
5175
Checker Message
single line: '5175'
Test Case #10
3 ms
704 KB
Accepted
Input
2754 81132
61606 30068 32995 48062 64467 58918 64616 3651 9570 40918 32425 42294 83869 19926 940 94536 63624 3763 28178 51657 32434 97764 44114 65656 1597 47106 54829 66447 98586 98832 66928 83123 56030 53711 94767 14432 7511 31867 39616 98777 10861...
Output
2744
Judge Output
2744
Checker Message
single line: '2744'
Test Case #11
4 ms
828 KB
Accepted
Input
3074 39444
83059 43806 90433 50133 31883 4125 45706 56660 31905 91100 1126 12691 31472 59069 14156 40670 45072 22678 62576 53307 19110 48317 58909 49354 37726 27614 18307 50529 69472 97187 8508 41159 879 76393 47038 21588 39857 89829 53676 25695 81...
Output
3074
Judge Output
3074
Checker Message
single line: '3074'
Test Case #12
4 ms
836 KB
Accepted
Input
4090 92852
28087 59021 25412 21503 9018 84238 69696 17858 4942 19430 28321 61089 99557 37961 36676 30004 33464 1652 83664 98952 48268 66733 17954 86446 89454 82527 45967 13051 58592 22643 10929 79683 99803 49378 83695 71338 38627 71688 53265 34095 7...
Output
4064
Judge Output
4064
Checker Message
single line: '4064'
Test Case #13
5 ms
832 KB
Accepted
Input
3083 71003
13804 16587 23317 42065 7831 87872 67596 39081 81975 37182 596 46590 65921 21667 23100 70154 31631 32721 9506 68351 54931 63433 7750 13299 96350 96891 66251 67016 52090 50624 95281 31297 89330 43373 53919 45595 68861 47393 43591 30727 802...
Output
3083
Judge Output
3083
Checker Message
single line: '3083'
Test Case #14
7 ms
712 KB
Accepted
Input
8903 44990
96022 94470 27458 72553 75692 53937 63000 42551 90366 24654 96261 8193 66126 60885 6888 65152 41686 46223 67263 26244 33946 56735 90834 10850 19074 50695 29605 3048 44617 29853 37589 36786 41916 38608 93433 50394 77588 12126 8135 24704 99...
Output
8881
Judge Output
8881
Checker Message
single line: '8881'
Test Case #15
7 ms
712 KB
Accepted
Input
8980 48018
50567 94179 23804 70373 39556 65516 8156 20158 24452 19444 85876 23673 76920 97189 32685 62188 1353 85935 90816 59409 37632 52256 56580 83841 86074 73271 83620 20183 98668 93673 58717 95809 95906 14525 28872 99232 66922 84436 71262 7458 9...
Output
8980
Judge Output
8980
Checker Message
single line: '8980'
Test Case #16
11 ms
716 KB
Accepted
Input
9488 43198
21383 44382 70980 47022 18703 27298 4239 39801 65795 81188 15263 28458 90502 79036 35632 82976 20937 15582 13619 12601 56530 39938 89087 34968 17598 16465 28883 71578 36667 74142 89616 66146 51885 42252 92526 49558 60908 48704 52429 75323...
Output
9488
Judge Output
9488
Checker Message
single line: '9488'
Test Case #17
11 ms
716 KB
Accepted
Input
8674 76670
61431 45077 45822 98719 65873 34497 96786 7876 14754 41640 18016 76294 52940 44781 83852 68217 95439 11804 88804 82313 36559 73045 66168 73716 32072 71121 90089 65386 85666 34936 3146 97775 38877 1213 56408 26860 59676 62673 99331 36583 4...
Output
8674
Judge Output
8674
Checker Message
single line: '8674'
Test Case #18
28 ms
1.2 MB
Accepted
Input
36066 677171648
139702117 763192327 878145513 92116014 221150347 88451586 371574856 882549406 832905030 973191740 286527015 477441292 522437928 697126419 742488723 157214487 633416638 125997550 428190274 712419531 869392529 619203641 735266740 99530...
Output
36066
Judge Output
36066
Checker Message
single line: '36066'
Test Case #19
332 ms
5.3 MB
Accepted
Input
397537 980426568
197782153 382116686 432351128 743605092 595325140 211473587 69167381 441732788 576567547 849627131 806448712 109978967 37559544 602078275 658848116 928268112 85208724 666978519 356536151 755711495 287298934 179634 375741358 1290555...
Output
397537
Judge Output
397537
Checker Message
single line: '397537'
Test Case #20
263 ms
12.4 MB
Accepted
Input
1000000 10
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
Output
1000000
Judge Output
1000000
Checker Message
single line: '1000000'