QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#621592 | #9447. Admired Person | ZhenLiu | WA | 0ms | 3664kb | C++14 | 989b | 2024-10-08 15:35:11 | 2024-10-08 15:35:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
int m ,n;
int am[5010];
int an[5010];
int flag[5010];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
for(int i=1; i<=n; ++i){
cin>>an[i];
flag[i]=0;
}
for(int i=1; i<=m; ++i)
cin>>am[i];
sort(am+1, am+m+1);
sort(an+1, an+n+1);
ll ans1=0;
for(int i=1; i<=m; ++i){
ll cha=INT_MAX, record;
for(int j=1; j<=n; ++j){
if(!flag[j]){
if(cha>abs(am[i]-an[j])){
record=j;
cha=abs(am[i]-an[j]);
}
}
}
flag[record]=1;
ans1 += cha;
}
for(int i=1; i<=n; ++i)
flag[i]=0;
ll ans2=0;
for(int i=m; i>=1; --i){
ll cha=INT_MAX, record;
for(int j=n; j>=1; --j){
if(!flag[j]){
if(cha>abs(am[i]-an[j])){
record=j;
cha=abs(am[i]-an[j]);
}
}
}
flag[record]=1;
ans2 += cha;
}
cout<<min(ans1, ans2)<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
5 3 2 6 5 1 1 6 3 8
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 2 1 1 9 1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
11 7 13 21 9 5 16 32 15 29 20 40 4 24 34 43 39 18 30 11
output:
32
result:
ok 1 number(s): "32"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
35 6 46 96 10 18 91 16 36 89 16 68 2 43 85 53 20 14 3 89 27 60 86 74 42 14 65 15 72 18 39 48 40 59 6 60 39 29 91 55 47 76 35
output:
8
result:
ok 1 number(s): "8"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
20 11 12 45 14 46 69 65 42 55 18 52 90 87 73 24 97 43 49 9 91 4 28 24 69 47 19 1 32 45 80 94 11
output:
40
result:
ok 1 number(s): "40"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
21 3 40 28 40 38 89 29 70 79 60 88 31 67 40 95 54 58 19 17 35 47 90 87 24 64
output:
8
result:
ok 1 number(s): "8"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
31 2 77 41 47 88 52 83 94 100 68 69 42 33 58 100 36 19 52 90 57 30 50 13 23 81 100 95 70 31 86 52 36 48 38
output:
3
result:
ok 1 number(s): "3"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
24 3 73 73 91 74 74 8 39 52 37 91 54 72 39 88 96 62 98 10 63 71 51 91 73 31 3 72 42
output:
8
result:
ok 1 number(s): "8"
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3592kb
input:
54 52 354567715 885423943 332278115 67046378 493302195 569363718 108877394 246293714 183721606 801281076 261093995 897683144 214239210 462059871 539384345 904212428 430249401 624234755 835419221 642763261 5641394 325620087 908461250 973232000 801026625 279494929 924527311 412579705 2405772 705362535...
output:
2835561434
result:
wrong answer 1st numbers differ - expected: '1902376181', found: '2835561434'