QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#618262 | #8034. Ban or Pick, What's the Trick | Pepinot | WA | 0ms | 3616kb | C++20 | 1.7kb | 2024-10-06 20:13:25 | 2024-10-06 20:13:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
void solve() {
int n,k; cin>>n>>k;
vector<int> a(n),b(n);
for(int i=0; i<n; i++) cin>>a[i];
for(int i=0; i<n; i++) cin>>b[i];
sort(a.begin(),a.end(),greater<int>());
sort(b.begin(),b.end(),greater<int>());
// for(auto i:a) cout<<i<<" ";
// cout<<endl;
// for(auto i:b) cout<<i<<" ";
// cout<<endl;
vector<int> va,vb;
int cnt_a=0,cnt_b=0;
// 9 7 6 4
// 10 8 5 2
for(int i=0; i<n; i++) {
if(a[cnt_a]==b[cnt_b]) {
va.push_back(a[cnt_a]);
vb.push_back(b[cnt_b]);
cnt_a++,cnt_b++;
continue;
}
//A bp
//ban
if((cnt_b<b.size()&&a[cnt_a]<b[cnt_b])||cnt_a>=a.size()||va.size()>=k)
cnt_b++;
//pick
else if((cnt_a<a.size()&&a[cnt_a]>b[cnt_b])||cnt_b>=b.size())
va.push_back(a[cnt_a]),cnt_a++;
//B bp
//ban
if((cnt_a<a.size()&&b[cnt_b]<a[cnt_a])||cnt_b>=b.size()||vb.size()>=k)
cnt_a++;
//pick
else if((cnt_b<b.size()&&b[cnt_b]>a[cnt_a])||cnt_a>=a.size())
vb.push_back(b[cnt_b]),cnt_b++;
}
// for(auto i:va) cout<<i<<" ";
// cout<<endl;
// for(auto i:vb) cout<<i<<" ";
// cout<<endl;
ll sum_a=0,sum_b=0;
for(int i=0; i<va.size()&&i<k; i++)
sum_a+=1ll*va[i];
for(int i=0; i<vb.size()&&i<k; i++)
sum_b+=1ll*vb[i];
// cout<<sum_a<<" "<<sum_b<<endl;
cout<<sum_a-sum_b;
}
int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
2 1 3 6 2 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
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: 3616kb
input:
4 2 4 6 7 9 2 5 8 10
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3552kb
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: 0ms
memory: 3600kb
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: 0ms
memory: 3536kb
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'