#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int k, n;
cin >> k >> n;
ll ans = 0;
vector<pair<int,int> > p;
for(int i = 0; i < n; i ++)
{
char P, Q;
int s, t;
cin >> P >> s >> Q >> t;
if(t < s) swap(s, t);
if(P == Q)
ans += t - s;
else
p.push_back({s, t});
}
ans += p.size();
if(k == 1)
{
vector<ll> v;
for(auto [x, y] : p)
{
v.push_back(x);
v.push_back(y);
}
sort(v.begin(), v.end());
ll testans = 1e18, suf = 0, sz = v.size();
for(ll i : v) suf += i;
ll prf = 0, cnt = 0;
for(ll i : v)
{
testans = min(testans, cnt * i - prf + suf - (sz - cnt) * i);
prf += i;
suf -= i;
cnt++;
}
ans += testans;
}
else
{
exit(0);
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |