Source Code
#include <iostream>
#include <vector>
#include <algorithm>
#define f first
#define s second
using namespace std;

pair < long long, long long>a[1000001];
void solve() {
	long long n, s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		cin >> a[i].f;
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i].s;
	}
	sort(a, a + n);
	int i = 0;
	for (i; i < n; i++) {
		s -= a[i].f;
		if (s <= 0) {
			break;
		}
		s += a[i].second;
	}
	cout << i;
}

int main() {
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}
Copy
Wheatly's portals - Hard version lafi-Odeh
GNU G++17
2 ms
848 KB
Wrong Answer