#include <bits/stdc++.h>
using namespace std;
// Idee 1 -> Set mit Wert|Index pair
// Idee 2 -> SegTree damit
void solve(){
int k; cin >> k;
int n; cin >> n;
vector<int> diff;
long long sum = 0;
for(int i = 0;i<n;i++){
char t1,t2;
int c1,c2;
cin >> t1 >> c1 >> t2 >> c2;
if(t1 == t2){
sum += abs(c2-c1);
}else{
diff.push_back(c1);
diff.push_back(c2);
}
}
if(diff.size() == 0){
cout << sum; return;
}
sort(diff.begin(),diff.end());
sum += (diff.size()/2);
int mid = diff[diff.size()/2] + diff[(diff.size()-1)/2];
mid/=2;
for(int i = 0;i<(int)diff.size();i++){
sum += abs(diff[i]-mid);
}
cout << sum << " ";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout << fixed << setprecision(8);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
19 ms |
1492 KB |
Output is correct |
13 |
Correct |
37 ms |
1476 KB |
Output is correct |
14 |
Correct |
27 ms |
1492 KB |
Output is correct |
15 |
Correct |
22 ms |
856 KB |
Output is correct |
16 |
Correct |
31 ms |
1476 KB |
Output is correct |
17 |
Correct |
26 ms |
1472 KB |
Output is correct |
18 |
Correct |
31 ms |
1488 KB |
Output is correct |
19 |
Correct |
35 ms |
1484 KB |
Output is correct |
20 |
Correct |
25 ms |
1384 KB |
Output is correct |
21 |
Correct |
34 ms |
1460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |