#include<iostream> usingnamespace std; #define int long long constint N = 55; voidsolve() { int n, k; cin >> n >> k; int a[N]; for (int i = 1; i <= n; i++) cin >> a[i]; int own = 0, ans = 0; for (int i = 1; i <= n; i++) { if (a[i] >= k) own += a[i];//收钱 elseif (a[i] == 0 && own > 0) own--, ans++;//发钱 } cout << ans << '\n'; } signedmain() { int t; cin >> t; while (t--) { solve(); } return0; }
#include<iostream> usingnamespace std; #define int long long voidsolve() { int n, k; cin >> n >> k; int ans = 0; if (k % 2) //如果k是奇数 ans += n % 2; if (k / 2 % 2)//有奇数个奇偶数对 ans += 1; if (ans % 2) cout << "NO" << '\n'; else cout << "YES" << '\n'; } signedmain() { int t; cin >> t; while (t--) { solve(); } return0; }
#include<iostream> #include<algorithm> usingnamespace std; #define int long long constint N = 2e5 + 10; int a[N]; voidsolve() { int n, sum = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; if (n == 1 || n == 2) { cout << -1 << '\n'; return; } sort(a + 1, a + n + 1); int ans = a[(n + 2) / 2] * 2 * n - sum + 1; if (ans <= 0) cout << 0 << '\n'; else cout << ans << '\n'; } signedmain() { int t; cin >> t; while (t--) { solve(); } return0; }
#include<iostream> #include<string> usingnamespace std; #define int long long constint N = 1e5 + 10; int R[N], L[N]; voidsolve() { memset(R, 0, sizeof R); memset(L, 0, sizeof L); int n, d, k; cin >> n >> d >> k; while (k--) { int l, r; cin >> l >> r; L[l]++, R[r]++; } //R记录 以该点为左端点在几个r的右边,即问它的左边(或加上自己)有几个r点 for (int i = 1; i <= n; i++) R[i] += R[i - 1]; //L记录 以该点为右端点在几个l的左边,即问它的右边(或加上自己)有几个l点 for (int i = n ; i >= 0; i--) L[i] += L[i + 1]; int t = 0, maxn = -0x3f3f3f3f, imax = 0, minn = 0x3f3f3f3f, imin = 0; for (int i = 1; i + d - 1 <= n; i++)//列举以每个点为左端点 { t = R[i - 1] + L[i + d]; if (t > maxn) imax = i, maxn = t; if (t < minn) imin = i, minn = t; } cout << imin << " " << imax << '\n'; } signedmain() { int t; cin >> t; while (t--) { solve(); } return0; }