# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
602573 | snasibov05 | Palembang Bridges (APIO15_bridge) | C++14 | 2 ms | 352 KiB |
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;
#define oo 1000000000
#define int long long
signed main() {
int k, n; cin >> k >> n;
int ans = 0;
vector<int> arr;
for (int i = 0; i < n; ++i){
char t1, t2; int x1, x2;
cin >> t1 >> x1 >> t2 >> x2;
if (t1 == t2) ans += abs(x2 - x1);
else arr.push_back(x1), arr.push_back(x2);
}
if (arr.size() == 0){
cout << ans << "\n";
return 0;
}
sort(arr.begin(), arr.end());
vector<int> pref(arr.size()); pref[0] = arr[0];
for (int i = 1; i < arr.size(); ++i) pref[i] = pref[i-1] + arr[i];
vector<int> suf(arr.size()); suf.back() = arr.back();
for (int i = arr.size() - 2; i >= 0; --i) suf[i] = suf[i+1] + arr[i];
int mn = oo;
for (int i = 0; i < arr.size(); ++i){
mn = min(mn, arr[i] * (i+1) - pref[i] + suf[i] - arr[i] * ((int)arr.size() - i));
}
ans += arr.size() / 2ll;
ans += mn;
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |