QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#368758#8034. Ban or Pick, What's the TrickhuangkehaiWA 0ms3672kbC++141.2kb2024-03-27 16:08:562024-03-27 16:15:45

Judging History

This is the latest submission verdict.

  • [2024-03-27 16:15:45]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3672kb
  • [2024-03-27 16:08:56]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 1e5+100;
int n,k;
int a[N],b[N];

bool cmp(int x,int y){
	return x>y;
}

//int s1[N],s2[N];

signed main(){
	cin>>n>>k;
	for (int i = 1; i <= n; i++) cin>>a[i];
	for (int i = 1; i <= n; i++) cin>>b[i];
	sort(a+1,a+n+1,cmp); sort(b+1,b+n+1,cmp);
	int l = 1 , r = 1;
	int cnt1 = 0  , cnt2 = 0;
	int s1 = 0  ,s2 = 0;
	bool f = 1;
	while (1){
		if (l > n){
			if (f == 1) r++;
			else{
				if (cnt2 < k) cnt2++,s2+=b[r];
				r++;
			}
			goto This;
		}
		if (r > n){
			if (f == 0) l++;
			else{
				if (cnt1 < k) cnt1++,s1+=a[l];
				l++;
			}
			goto This;
		}
		if (a[l] >= b[r]){
			if (f == 1){
				if (cnt1 < k && a[l] > b[r]) cnt1++,s1+=a[l],l++;
				else r++;
			}
			else{
				if (cnt1 == k && cnt2 < k) s2+=b[r],r++,cnt2++;
				else l++;
			}
 		}
 		else{
 			if (f  == 0){
 				if (cnt2 < k) cnt2++,s2+=b[r],r++;
 				else l++;
			 }
			 else{
			 	if (cnt2 == k && cnt1 < k) s1+=a[l],l++,cnt1++;
			 	else r++;
			 }
		 }
		 This:;
		 if (l > n && r > n) break;
		 if (cnt1 == k && cnt2 == k) break;
		 f^=1;
	}
	cout<<s1-s2;
}

詳細信息

Test #1:

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

input:

2 1
3 6
2 4

output:

2

result:

ok single line: '2'

Test #2:

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

input:

4 1
1 3 5 7
2 4 6 8

output:

0

result:

ok single line: '0'

Test #3:

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

input:

4 2
4 6 7 9
2 5 8 10

output:

3

result:

ok single line: '3'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3596kb

input:

10 5
42 13 60 42 100 82 22 98 14 55
100 41 89 24 65 38 69 26 37 16

output:

39

result:

wrong answer 1st lines differ - expected: '41', found: '39'