1 solutions

  • 2
    @ 2025-11-22 11:18:33
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    const int N = 2e5 + 10;
    int n, x, y;
    int a[N], b[N];
    int a1 = 0, b1 = 0, m = 0;
    
    signed main() {
    	cin >> n >> x >> y;
    	for (int i = 1; i <= n; i++) {
    		cin >> a[i];
    	}
    	sort(a + 1, a + n + 1);
    	for (int i = 1; i <= n; i++) {
    		cin >> b[i];
    	}
    	sort(b + 1, b + n + 1);
    	for (int i = n; i > 0; i--) {
    		m++;
    		a1 += a[i];
    		b1 += b[i];
    		if (a1 > x || b1 > y) {
    			cout << m << '\n';
    			return 0;
    		}
    	}
    	cout << m << '\n';
    	return 0;
    }
    
    
    
    • 1

    Information

    ID
    18134
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    # Submissions
    87
    Accepted
    40
    Uploaded By