#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef pair <ll, ll> pii;
int k, n;
int main () {
cin >> k >> n;
ll res = 0;
vector <pii> v;
for (int i = 0; i < n; i++) {
char ca, cb;
ll a, b;
cin >> ca >> a >> cb >> b;
if (a > b) swap(a, b);
if (ca != cb) v.pb({a, b});
res += b-a;
}
int m = v.size();
if (k == 1) {
ll com = 0;
multiset <ll> s;
for (auto it : v) {
com += it.F;
s.insert(it.F);
s.insert(it.S);
}
ll la = 0, sl = -m, sol = 1e18;
for (auto it : s) {
com += (it - la)*sl;
sl++;
la = it;
sol = min(sol, com);
}
cout << 2*sol+m+res;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |