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>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const ll inf = 1e18;
vector<pair<int, int> > eve;
ll solve(){
int n = eve.size();
vector<ll> a(2 * n + 1);
for (int i = 0; i < n; i++){
a[2 * i + 0 + 1] = eve[i].first;
a[2 * i + 1 + 1] = eve[i].second;
}
sort(a.begin() + 1, a.end());
n = 2 * n;
for (int i = 1; i <= n; i++)
a[i] += a[i - 1];
ll answer = inf;
for (int i = 1; i <= n; i++){
ll T = a[i] - a[i - 1];
answer = min(answer, T * (i - (n - i)) - a[i] + (a[n] - a[i]));
}
return answer + eve.size();
}
int main(){
ios_base::sync_with_stdio(false);
int k, n;
cin >> k >> n;
ll answer = 0;
for (int i = 0; i < n; i++){
int x, y;
char a, b;
cin >> a >> x >> b >> y;
if (a == b){
answer += abs(x - y);
continue;
}
if (a == 'B')
swap(x, y);
eve.push_back({x, y});
}
if (k == 1){
cout << answer + solve() << '\n';
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... |