#include<bits/stdc++.h> #define int long long #define fr first #define se second usingnamespace std; typedef pair<int, int> PII; constint N = 2010; PII f[N]; boolcmp(PII a, PII b){ return a.se < b.se; } voidsolve() { int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> f[i].fr >> f[i].se; sort(f + 1, f + 1 + n, cmp); int res = 0; for(int i = 1; i <= n; i++) { priority_queue<int> q; int sum = 0; for(int j = i; j <= n; j++) { q.push(f[j].fr); sum += f[j].fr; while(!q.empty() && sum + f[j].se - f[i].se > k){ sum -= q.top(); q.pop(); } res = max((int)q.size(), res); } } cout << res << endl; } signedmain() { int T; cin >> T; while(T--) solve(); return0; }
#include<bits/stdc++.h> #define int long long #define fr first #define se second usingnamespace std; typedef pair<int, int> PII; constint N = 300010; int a[N]; voidsolve() { int n, m; cin >> n >> m; int res = m * (m + 1) / 2 + m + 1; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); int cnt1 = 0, cnt2 = 0; for(int i = 1; i <= n; i++){ int t = a[i]; res -= m - t + 1; res -= t / 2; if(t % 2) res += cnt1, cnt1++; else res += cnt2, cnt2 ++; } cout << res << endl; } signedmain() { int T; cin >> T; while(T--) solve(); return0; }