QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#802081#9873. Last Chance: Threads of Despairucup-team5008#WA 1ms3856kbC++231.7kb2024-12-07 11:51:192024-12-07 11:51:19

Judging History

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

  • [2024-12-07 11:51:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3856kb
  • [2024-12-07 11:51:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const ll inf=LLONG_MAX/4;
#define rep2(i,j,k) for(ll i=ll(j);i<ll(k);i++)
#define rep(i,k) rep2(i,0,k)
#define rrep2(i,j,k) for(ll i=ll(j)-1;i>=ll(k);i--)
#define rrep(i,k) rrep2(i,k,0)
#define eb emplace_back
#define SZ(a) ll(a.size())
#define all(a) a.begin(),a.end()
template<class T>
bool chmin(T& a, T b){return a>b ? a=b,1:0;}
template<class T>
bool chmax(T& a, T b){return a<b ? a=b,1:0;}

void solve(){
	ll n,m;cin>>n>>m;
	ll exp=0;
	map<ll,ll> a,b;
	vl oa;
	rep(i,n){
		ll x;cin>>x;
		oa.eb(x);
		a[x]++;
	}
	rep(i,m){
		ll x;cin>>x;
		b[x]++;
	}
	auto upd=[&](){
		while(true){
			bool flag = false;
			while(!a.empty()){
				auto na=*a.begin();
				if(na.first>exp) break;
				exp += na.second;
				flag=true;
				a.erase(na.first);
			}
			while(!b.empty()){
				auto nb=*b.begin();
				if(nb.first>exp) break;
				exp += nb.second;
				flag=true;
				b.erase(nb.first);
			}
			if(!flag) break;
		}
	};
	auto print=[&](){
		return;
		cout << exp << endl;
		for(auto el: a){
			rep(i,el.second) cout << el.first << " ";
		}
		cout << endl;
		for(auto el: b){
			rep(i,el.second) cout << el.first << " ";
		}
		cout << endl;
	};
	sort(all(oa));
	for(auto na: oa){
		if(na <= exp || b.empty()) continue;
		ll nb;
		if(na < exp+a[na]) nb=(*b.rbegin()).first;
		else nb = (*b.begin()).first;
		a[na]--;
		b[nb]--;
		if(a[na] == 0) a.erase(na);
		if(b[nb] == 0) b.erase(nb);
		a[na-1]++;
		b[nb-1]++;
		upd();
		print();
	}
	string ans="No";
	if(b.empty()) ans="Yes";
	cout << ans << "\n";
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	ll t;cin>>t;
	while(t--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

input:

3
3 2
1 1 4
2 6
3 2
1 1 4
2 7
2 1
100 100
2

output:

Yes
No
Yes

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

3
7 1
1 1 1 1 1 1 1
9
5 2
3 4 5 6 7
1 6
5 3
3 4 5 6 7
1 5 7

output:

No
No
Yes

result:

ok 3 token(s): yes count is 1, no count is 2

Test #3:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

4
1 1
1
1
1 1
1
2
1 1
2
1
1 1
2
2

output:

Yes
Yes
Yes
No

result:

ok 4 token(s): yes count is 3, no count is 1

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3856kb

input:

18
1 2
1
1 1
1 2
1
2 1
1 2
1
1 3
1 2
1
2 2
1 2
1
3 2
1 2
1
3 3
1 2
2
1 1
1 2
2
1 2
1 2
2
1 3
1 2
2
2 2
1 2
2
2 3
1 2
2
3 3
1 2
3
1 1
1 2
3
1 2
1 2
3
1 3
1 2
3
2 2
1 2
3
3 2
1 2
3
3 3

output:

Yes
Yes
No
Yes
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
No
No

result:

wrong answer expected YES, found NO [3rd token]