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

int n, s, a1[1000000], a2[1000000], ans = 0;
pair<int, int> a[1000000];
int main(){
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	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 = 0, k = n-1; i < n; ++i)
	{
		a2[i] = a1[k];
		k--;
	}
	// for (int i = 0; i < n; ++i)
	// {
	// 	cout << a2[i] << " ";
	// }
	for (int i = 0; i < n; ++i)
	{
		s += a2[i];
		if (s <= 0)
		{
			break;
		}
		ans++;
	}
	cout << ans;



	return 0;

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