QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#73404#3025. Assimilationzhangboju#WA 125ms13008kbC++14789b2023-01-25 09:02:182023-01-25 09:02:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-25 09:02:21]
  • 评测
  • 测评结果:WA
  • 用时:125ms
  • 内存:13008kb
  • [2023-01-25 09:02:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x)
{
	x=0;short f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x*=f;return;
}
#define ll long long
int n,k;
multiset<int>S;
int main()
{
	int T;read(T);
	while(T--)
	{
		read(n),read(k);
		S.clear();
		ll sum=0;
		for(int i=1,x;i<=n;++i)
			read(x),sum+=x,S.insert(x);
		int ans=0;
		while(S.size()&&sum>k)
		{
			auto it=S.lower_bound(k);
			if(it==S.end()) it=prev(it);
			if(*it>k)
			{
				if(it!=S.begin()) it=prev(it);
				else break;
			}
			if(*it>k) break;
			ll x=*it;
			k+=x,sum-=x,++ans;
			S.erase(it);
		} 
		if(sum>k) puts("-1");
		else printf("%d\n",ans);
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 125ms
memory: 13008kb

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
-1
4
-1
7
5385
-1
2
-1
5
6264
3
0
-1
-1
5
-1
7
10940
1
3
100000
5
-1
-1

result:

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