Source Code
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;
int diff[1000000];
pair<int, int> a[1000000];

int main(){
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	

	int n, s;
	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)
	{
		diff[i] = a[i].second - a[i].first;
	}
	sort(diff, diff + n);
	
	int ans = 1;
	for (int i = n -1; i >= 0; --i)
	{
		s += diff[i];
		if (s <= 0)
		{
			break;
		}else{
			ans++;
		}
	}
	cout << ans;


	return 0;
}
Copy
Wheatly's portals - Easy version microwave6
GNU G++17
1 ms
244 KB
Wrong Answer