Submission #146173

#TimeUsernameProblemLanguageResultExecution timeMemory
146173mhy908Palembang Bridges (APIO15_bridge)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
LL temp, ans=987654321987654321;
int n, re, k;
LL arr[200010], sum[200010];
int re2;
pll input[100010];
LL lef, rig, mid;
priority_queue<LL> l, r;
void in_pq(LL a)
{
    if(mid<=a){
        r.push(-a);
        rig+=a;
    }
    else{
        l.push(b);
        lef+=b;
    }
    if(r.size()>=l.size()+2){
        LL temp=-r.top();
        r.pop();
        rig-=temp;
        l.push(mid);
        lef+=mid;
        mid=temp;
    }
    if(r.size()+2<=l.size()){
        LL temp=l.top();
        l.pop();
        lef-=temp;
        r.push(-mid);
        rig+=mid;
        mid=temp;
    }
}
LL solve()
{
    return mid*l.size()-lef+rig-mid*r.size();
}
int main()
{
    scanf("%d %d", &k, &n);
    for(int i=1; i<=n; i++){
        char a, b;
        LL c, d;
        scanf(" %c %lld %c %lld", &a, &c, &b, &d);
        if(a==b)temp+=llabs(c-d);
        else{
            arr[++re]=c;
            arr[++re]=d;
            input[++re2]={min(c, d), max(c, d)};
        }
    }
    sort(arr+1, arr+re+1);
    sort(input+1, intput+re2+1, [](const pll& a, const pll& b){return a.F+a.S<b.F+b.S});
    for(int i=1; i<=re; i++){
        sum[i]=sum[i-1]+arr[i];
    }
    if(k==1){
        ans=sum[re]-sum[re/2]*2;
        printf("%lld", ans+temp+(LL)re/2);
        return 0;
    }
    mid=input[i].F;
    in_pq(input[1].S);
    arr[1]=solve();
    for(int i=2; i<=re2; i++){
        in_pq(input[i].F);
        in_pq(input[i].S);
        arr[i]=solve();
    }
    lef=0;
    rig=0;
    l.clear();
    r.clear();
    mid=input[re2].F;
    in_pq(input[re2].S);
    arr[n]+=solve();
    for(int i=re2-1; i>=1; i--){
        in_pq(input[i].F);
        in_pq(input[i].S);
        arr[i]+=solve();
        ans=min(ans, arr[i]);
    }
    printf("%lld", ans+temp+(LL)re/2);
}

Compilation message (stderr)

bridge.cpp: In function 'void in_pq(LL)':
bridge.cpp:23:16: error: 'b' was not declared in this scope
         l.push(b);
                ^
bridge.cpp: In function 'int main()':
bridge.cpp:62:19: error: 'intput' was not declared in this scope
     sort(input+1, intput+re2+1, [](const pll& a, const pll& b){return a.F+a.S<b.F+b.S});
                   ^~~~~~
bridge.cpp:62:19: note: suggested alternative: 'input'
     sort(input+1, intput+re2+1, [](const pll& a, const pll& b){return a.F+a.S<b.F+b.S});
                   ^~~~~~
                   input
bridge.cpp: In lambda function:
bridge.cpp:62:86: error: expected ';' before '}' token
     sort(input+1, intput+re2+1, [](const pll& a, const pll& b){return a.F+a.S<b.F+b.S});
                                                                                      ^
bridge.cpp: In function 'int main()':
bridge.cpp:71:15: error: 'i' was not declared in this scope
     mid=input[i].F;
               ^
bridge.cpp:81:7: error: 'class std::priority_queue<long long int>' has no member named 'clear'
     l.clear();
       ^~~~~
bridge.cpp:82:7: error: 'class std::priority_queue<long long int>' has no member named 'clear'
     r.clear();
       ^~~~~
bridge.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &k, &n);
     ~~~~~^~~~~~~~~~~~~~~~~
bridge.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c %lld %c %lld", &a, &c, &b, &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~