QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#752127#8034. Ban or Pick, What's the TrickUnalomeWA 0ms3624kbC++20784b2024-11-15 22:06:092024-11-15 22:06:10

Judging History

This is the latest submission verdict.

  • [2024-11-15 22:06:10]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3624kb
  • [2024-11-15 22:06:09]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
typedef long long ll;
const int N=1e5+5;

int n,k,a[N],b[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    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+1+n);
    sort(b+1,b+1+n);

    int p1=n,p2=n;

    vector<int> s1,s2;
    for(int i=1;i<=2*n;i++) {
        if(i&1) {
            if(a[p1]>b[p2]) s1.pb(a[p1]),p1--;
            else p2--;
        } else {
            if(b[p2]>a[p1]) s2.pb(b[p2]),p2--;
            else p1--;
        }
    }

    ll sum1=0,sum2=0;
    for(int i=0;i<s1.size()&&i<k;i++) sum1+=s1[i];
    for(int i=0;i<s2.size()&&i<k;i++) sum2+=s2[i];

    cout<<sum1-sum2;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1
3 6
2 4

output:

2

result:

ok single line: '2'

Test #2:

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

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: 3624kb

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: 3624kb

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'