QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#66519#3025. AssimilationyoIAWA 172ms14284kbC++141.9kb2022-12-08 20:46:302022-12-08 20:46:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-08 20:46:31]
  • 评测
  • 测评结果:WA
  • 用时:172ms
  • 内存:14284kb
  • [2022-12-08 20:46:30]
  • 提交

answer

#include <bits/stdc++.h>
#define forn(i,s,t) for(int i=(s); i<=(t); ++i)
#define form(i,s,t) for(int i=(s); i>=(t); --i)
#define rep(i,s,t) for(int i=(s); i<(t); ++i)
using namespace std;
typedef double f64;
typedef long long i64;
typedef unsigned long long u64;
const int N = 2e5 + 3, M = 1e6 + 4, Mod = 998244353;
struct mint {
	int r;
	mint() {}
	mint(int _r) : r(_r) {}
	inline friend mint operator + (const mint& A, const mint& B) {
		return mint((A.r + B.r >= Mod) ? (A.r + B.r - Mod) : (A.r + B.r));
	}
	inline friend mint operator - (const mint& A, const mint& B) { return A + mint(Mod - B.r); }
	inline friend mint operator * (const mint& A, const mint& B) { return mint(1ll * A.r * B.r % Mod); }
	inline friend mint& operator += (mint& A, const mint& B) { return A = A + B; }
	inline friend mint& operator -= (mint& A, const mint& B) { return A = A - B; }
	inline friend mint& operator *= (mint& A, const mint& B) { return A = A * B; }
	inline friend mint q_pow(mint p, int k = Mod - 2) {
		mint r = 1;
		for (; k; k >>= 1, p *= p) (k & 1) && (r *= p, 0);
		return r;
	}
};
int n; i64 k, a[N];
multiset<i64> S, T;
inline void init() {
	S.clear(), T.clear();
}
inline void solve() {
	cin >> n >> k;
	forn (i, 1, n) cin >> a[i], S.insert(a[i]);
	int ans = 0;
	while (!S.empty()) {
		if (k >= *S.rbegin()) break ;
		auto it = S.upper_bound(k);
		if (it == S.begin()) break ;
		--it;
		ans ++ ;
		k += *it, S.erase(it);
	}
	if (k < *S.rbegin()) {
		return cout << "-1\n", void();
	}
	while (!S.empty()) {
		while (!T.empty() && k < *S.rbegin()) {
			k += *(--T.end());
			T.erase(--T.end());
			ans ++ ;
		}
		k -= *S.rbegin();
		T.insert(*S.rbegin()), S.erase(--S.end());
	}
	cout << ans << '\n';
}
int z;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> z;
	while (z--) init(), solve();
	return 0;
} 
/*
*/

详细

Test #1:

score: 0
Wrong Answer
time: 172ms
memory: 14284kb

input:

29
9 1
1 1 2 1 1 1 1 1 1
4 1
3 2 1 1
5 316660370
269357435 105688553 346785866 295093544 181703417
6 43402885
39947441 27068237 43810814 44913378 40095941 34779892
22 319594
3815194 3056481 6593888 7315914 6593888 4794774 2561877 5256242 4920603 5256242 3606645 864746 1594265 1235578 2361430 2277526...

output:

7
2
2
4
-1
24932
4
-1
11
24350
17
2
-1
8
24550
4
0
-1
199755
9
-1
13
24943
1
4
199999
6
-1
-1

result:

wrong answer 1st lines differ - expected: '4', found: '7'