QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#14393#3025. AssimilationzinWA 208ms13852kbC++17772b2021-10-05 22:37:262022-05-17 00:27:39

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:39]
  • 评测
  • 测评结果:WA
  • 用时:208ms
  • 内存:13852kb
  • [2021-10-05 22:37:26]
  • 提交

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;
int 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 > k) {
				if (iter != st.begin()) iter = prev(iter);
				else 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: 208ms
memory: 13852kb

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'