# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
682519 | 79brue | Palembang Bridges (APIO15_bridge) | C++17 | 62 ms | 6316 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;
typedef long long ll;
int n, k;
ll base, ans;
ll a[100002], b[100002];
int main(){
scanf("%d %d", &k, &n);
for(int i=1; i<=n; i++){
char C1, C2;
int X1, X2;
scanf(" %c %d %c %d", &C1, &X1, &C2, &X2);
if(C1==C2) base += abs(X1-X2), n--, i--;
else a[i] = X1, b[i] = X2;
}
if(n==0){
printf("%lld", base);
return 0;
}
if(k==1){
vector<ll> vec;
for(int i=1; i<=n; i++) vec.push_back(a[i]), vec.push_back(b[i]);
sort(vec.begin(), vec.end());
ans = 1e18;
ll lsum = 0, lcnt = 0, rsum = accumulate(vec.begin(), vec.end(), 0LL), rcnt = (int)vec.size();
for(int i=0; i<n*2; i++){
rsum -= vec[i], rcnt--;
ans = min(ans, (lcnt * vec[i] - lsum) + (rsum - rcnt * vec[i]) + n);
lsum += vec[i], lcnt++;
}
printf("%lld", ans+base);
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... |