QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281626#3025. AssimilationDualqwq#WA 225ms14480kbC++20703b2023-12-10 14:31:062023-12-10 14:31:06

Judging History

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

  • [2023-12-10 14:31:06]
  • 评测
  • 测评结果:WA
  • 用时:225ms
  • 内存:14480kb
  • [2023-12-10 14:31:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
long long k,a[N];
multiset<int> S1,S2;
inline void work() {
	cin >> n >> k;
	for(int i = 1;i <= n;i++) cin >> a[i];
	S1.clear(),S2.clear();
	int ans = 0;
	for(int i = 1;i <= n;i++) S1.insert(a[i]);
	while(S1.size()) {
		if(k >= *S1.begin()) {
			auto it = S1.upper_bound(k);
			--it;
			// printf("zhan:%d\n",*it);
			k -= *it;S2.insert(*it);S1.erase(it);
		} else if(S2.size()) {
			k += 2 * (*S2.rbegin());
			S2.erase(prev(S2.end()));
			++ans;
		} else break;
	}
	if(S1.size()) cout << -1 << endl;
	else cout << ans << endl;
}
int main() {
	int T;
	cin >> T;
	while(T--) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 225ms
memory: 14480kb

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:

4
2
2
3
-1
10621
4
-1
7
5385
8
2
-1
5
6264
3
0
-1
124835
5
-1
7
10940
1
3
100000
5
-1
-1

result:

wrong answer 19th lines differ - expected: '124764', found: '124835'