B1. K for the Price of One (Easy Version):题目
两种情况,前面取一或者前面不取
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> a((int)6e5);
vector<int> b((int)6e5), c((int)6e5);
const int mod = 1e9 + 7;
string s;
signed main()
{int t;cin >> t;while (t--){int n, p, k;cin >> n >> p >> k;for (int i = 0; i < n; i++)cin >> a[i];sort(a.begin(), a.begin() + n);a[n] = (int)2e9;int res = 0;int np = p;for (int i = 0; i < n; i += 2){if (a[i + 1] <= p){p -= a[i + 1];res += 2;}else if (a[i] <= p){p -= a[i];res++;}}int nres = 0;if (np >= a[0]){np -= a[0];nres = 1;}for (int i = 1; i < n; i += 2){if (a[i + 1] <= np){np -= a[i + 1];nres += 2;}else if (a[i] <= p){np -= a[i];nres++;}}cout << max(res, nres) << endl;}
}