QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#14395#3025. AssimilationzinWA 218ms14480kbC++17824b2021-10-05 22:44:212022-05-17 00:27:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-17 00:27:45]
  • 评测
  • 测评结果:WA
  • 用时:218ms
  • 内存:14480kb
  • [2021-10-05 22:44:21]
  • 提交

answer

#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using t4 = tuple<ll, ll, ll, ll>;

int Z, N, K;
ll arr[220000];

int main() {
	cin >> Z;
	while (Z--) {
		cin >> N >> K;
		for (int i = 0; i < N; i++) cin >> arr[i];
		multiset<int> st;
		ll sum = 0, k = K;
		for (int i = 0; i < N; i++) st.insert(arr[i]), sum += arr[i];
		int ans = 0;
		while (st.size() && sum > k) {
			auto iter = st.lower_bound(k);
			if (iter == st.end()) iter = prev(iter);
			if (*iter > k) {
				if (iter != st.begin()) iter = prev(iter);
				else break;
			}
			if (*iter > k) break;

			k += *iter;
			sum -= *iter;
			st.erase(iter);
			ans++;
		}
		if (sum > k) cout << -1 << '\n';
		else cout << ans << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 218ms
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
13566
4
-1
7
5385
9
2
-1
5
6264
3
0
-1
125010
5
-1
7
10940
1
3
100000
5
-1
-1

result:

wrong answer 6th lines differ - expected: '10621', found: '13566'