| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 43390 | top34051 | Palembang Bridges (APIO15_bridge) | C++14 | 81 ms | 2284 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 ll long long
const int maxn = 2e5 + 5;
int n,m,k,sz;
int a[maxn], b[maxn];
int pos[maxn];
ll solve1() {
    ll res = 0;
    sz = 0;
    for(int i=1;i<=n;i++) pos[sz++] = a[i], pos[sz++] = b[i];
    sort(&pos[0],&pos[sz]);
    int opt = pos[sz/2];
    for(int i=0;i<sz;i++) res += abs(opt-pos[i]);
    return res;
}
int main() {
    long long extra = 0;
    scanf("%d%d",&k,&n);
    for(int i=1;i<=n;i++) {
        int x, y; char t1, t2;
        scanf(" %c%d %c%d",&t1,&x,&t2,&y);
        if(t1==t2) extra += abs(x-y);
        else {
            m++;
            a[m] = x; b[m] = y;
            extra++;
        }
    }
    n = m;
    printf("%lld",extra + solve1());
}
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... | ||||
