#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
int n,k;
int a[maxn];
long long s[maxn];
long long sol=0;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>k>>n;
int br=1;
for(int i=0;i<n;i++)
{
char h,j;
int x,y;
cin>>h>>x>>j>>y;
if(h==j)sol+=abs(x-y);
else{
a[br]=x;
br++;
a[br]=y;
br++;
}
}
n=br;
sort(a+1,a+n);
s[0]=0LL;
for(int i=1;i<n;i++)s[i]=s[i-1]+a[i];
if(k==1)
{
int mo=a[n/2];
cout<<sol + 1LL*mo*(n/2 - 1)-s[n/2 - 1] + s[n-1]-s[n/2]-1LL*mo*(n-1-n/2) + (n-1)/2<<endl;
return 0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
472 KB |
Output is correct |
5 |
Correct |
2 ms |
540 KB |
Output is correct |
6 |
Correct |
2 ms |
564 KB |
Output is correct |
7 |
Correct |
2 ms |
584 KB |
Output is correct |
8 |
Correct |
3 ms |
608 KB |
Output is correct |
9 |
Correct |
2 ms |
816 KB |
Output is correct |
10 |
Correct |
2 ms |
816 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
856 KB |
Output is correct |
3 |
Correct |
2 ms |
856 KB |
Output is correct |
4 |
Correct |
3 ms |
856 KB |
Output is correct |
5 |
Correct |
3 ms |
932 KB |
Output is correct |
6 |
Correct |
2 ms |
932 KB |
Output is correct |
7 |
Correct |
2 ms |
932 KB |
Output is correct |
8 |
Correct |
2 ms |
932 KB |
Output is correct |
9 |
Correct |
3 ms |
976 KB |
Output is correct |
10 |
Correct |
2 ms |
976 KB |
Output is correct |
11 |
Correct |
3 ms |
976 KB |
Output is correct |
12 |
Correct |
33 ms |
4072 KB |
Output is correct |
13 |
Correct |
52 ms |
6320 KB |
Output is correct |
14 |
Correct |
38 ms |
7320 KB |
Output is correct |
15 |
Correct |
31 ms |
7992 KB |
Output is correct |
16 |
Correct |
36 ms |
10640 KB |
Output is correct |
17 |
Correct |
40 ms |
12944 KB |
Output is correct |
18 |
Correct |
50 ms |
14884 KB |
Output is correct |
19 |
Correct |
51 ms |
17216 KB |
Output is correct |
20 |
Correct |
37 ms |
19152 KB |
Output is correct |
21 |
Correct |
73 ms |
21176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
21176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
21176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
21176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |