답안 #1094802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094802 2024-09-30T15:31:42 Z Octa_pe_info Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 432 KB
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

multiset<int>st,dr;

bool cmp(pair<int,int>a,pair<int,int>b) {

    return a.first + a.second < b.first + b.second;

}

int ssum=0,dsum=0;

void adauga(int nr) {

    int mid = st.size() == 0 ? 10000001 : *st.rbegin();

    if(nr <= mid)
        st.insert(nr),ssum+=nr;
    else dr.insert(nr),dsum+=nr;

    if(dr.size() + 1 < st.size()) {

        int auxs = *st.rbegin();
        dr.insert(auxs);
        st.erase(auxs);
        ssum-=auxs;
        dsum+=auxs;

    } else if(st<dr) {

        int auxs = *dr.rbegin();
        st.insert(auxs);
        dr.erase(auxs);
        dsum-=auxs;
        ssum+=auxs;

    }

}

int main() {

    int n,k;
    cin>>n>>k;

    vector<pair<int,int>>poz;

    int ans = 0,fel=0;

    for(int i=1; i<=n; i++) {

        int a,b;
        char c,cc;
        cin>>c>>a>>cc>>b;

        if(c == cc)
            fel+= abs(a-b);
        else poz.push_back({a,b});

    }

    sort(poz.begin(),poz.end(),cmp);

    fel+= poz.size();

    vector<int>api(poz.size());

    for(int i=0; i<poz.size(); i++) {

        adauga(poz[i].first);
        adauga(poz[i].second);
        api[i] = dsum - ssum;

    }

    ans = api[poz.size()-1];

    if(k == 2) {

        st.clear();
        dr.clear();

        for(int i = poz.size()-1; i>=0; i--) {

            adauga(poz[i].first);
            adauga(poz[i].second);
            ans = min(ans,dsum - ssum + api[i-1]);

        }

    }

    cout<<ans+fel;

    return 0;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i=0; i<poz.size(); i++) {
      |                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -