This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int k, n;
cin >> k >> n;
int ans = 0;
vector<int> a, b;
for (int i = 0; i < n; i++) {
char p, q;
int s, t;
cin >> p >> s >> q >> t;
if (p == q) {
ans += abs(s - t);
} else {
if (p == 'A') {
a.push_back(s);
b.push_back(t);
} else {
a.push_back(t);
b.push_back(s);
}
}
}
if (k == 1) {
int m = (int)a.size();
vector<int> c;
for (int i = 0; i < m; i++) {
c.push_back(a[i]);
c.push_back(b[i]);
}
sort(c.begin(), c.end());
for (int i = 0; i < 2 * m; i++) {
ans += abs(c[i] - c[m]);
}
cout << ans << '\n';
return 0;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |