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];
	
		if (s <= 0)
		{
			break;
		}
			ans++;
	}
	cout << ans;



	return 0;

}
Copy
Wheatly's portals - Hard version microwave6
GNU G++17
493 ms
12.4 MB
Wrong Answer