QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549023 | #8034. Ban or Pick, What's the Trick | ucup-team3474 | WA | 1ms | 7876kb | C++20 | 1.6kb | 2024-09-06 00:35:39 | 2024-09-06 00:35:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],b[N];
char s[N];
void __(){
cin>>n>>k;
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
sort(a+1,a+1+n);
sort(b+1,b+1+n);
int i=n,j=n;
int cnt1=0,cnt2=0;
ll ans1=0,ans2=0;
int now=0;
while(i>0||j>0){
if(!now){
if(cnt1<k){
if(j==0){
cnt1++;
ans1+=a[i--];
}else if(i==0){
j--;
}else{
if(a[i]>=b[j]||cnt2>=k){
cnt1++;
ans1+=a[i--];
}else j--;
}
}else{
if(j!=0) j--;
else i--;
}
}else{
if(cnt2<k){
if(i==0){
cnt2++;
ans2+=b[j--];
}else if(j==0){
i--;
}else{
if(a[i]<=b[j]||cnt1>=k){
cnt2++;
ans2+=b[j--];
}else i--;
}
}else{
if(i!=0) i--;
else j--;
}
}
// cout<<ans1<<" "<<ans2<<endl;
now^=1;
}
cout<<ans1-ans2<<endl;
}
int main(){
int _=1;
// cin>>_;
while(_--){
__();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7720kb
input:
2 1 3 6 2 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7820kb
input:
4 1 1 3 5 7 2 4 6 8
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7732kb
input:
4 2 4 6 7 9 2 5 8 10
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7860kb
input:
10 5 42 13 60 42 100 82 22 98 14 55 100 41 89 24 65 38 69 26 37 16
output:
41
result:
ok single line: '41'
Test #5:
score: 0
Accepted
time: 1ms
memory: 7876kb
input:
9 10 4 32 566 885 439 479 332 95 432 409 140 704 26 558 781 457 356 404
output:
58
result:
ok single line: '58'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 7860kb
input:
20 8 249 888 548 338 840 890 519 416 852 817 28 694 271 947 239 11 654 914 765 939 483 148 403 552 250 635 287 644 364 822 621 151 31 422 683 959 867 266 837 395
output:
1241
result:
wrong answer 1st lines differ - expected: '1201', found: '1241'