# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
971762 | Halym2007 | Palembang Bridges (APIO15_bridge) | C++17 | 4 ms | 2396 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"
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define sz size()
const int N = 2e5 + 1;
using namespace std;
int k, n, vis[N];
ll mn = 1e15, sum, cnt, p[N];
pair <char, int> a[N], b[N];
vector <ll> v;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> k >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
if(a[i].ff != b[i].ff) {
cnt++;
v.pb(b[i].ss);
v.pb(a[i].ss);
}
else sum += abs(a[i].ss-b[i].ss);
}
sort(v.begin(), v.end());
for(int i = 0; i < v.sz; i++){
p[i+1] = v[i] + p[i];
}
for(ll i = 0; i < v.sz; i++){
mn = min(mn, (i + 1) * v[i] - p[i+1] + p[(ll)v.sz] - p[i+1] - ((ll)v.sz - i - 1)*v[i] );
}
cout << mn + sum + cnt;
}
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... |