제출 #1060004

#제출 시각아이디문제언어결과실행 시간메모리
1060004PiokemonCloud Computing (CEOI18_clo)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr int N = 2000;
ll kompy[N+9][3]; // ile f koszt
ll osoby[N+9][3];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n;
    bool c1=1;
    for (int x=1;x<=n;x++){
        cin >> kompy[x][0] >> kompy[x][1] >> kompy[x][2];
        if (kompy[x][0]>1)c1=0;
    }
    cin >> m;
    for (int x=1;x<=m;x++){
        cin >> osoby[x][0] >> osoby[x][1] >> osoby[x][2];
        if (osoby[x][0]>1)c1=0;
    }
    if (c1){
        vector<pair<ll,ll>> kup;
        priority_queue<ll> mozl;
        vector<pair<ll,ll>> oso;
        for (int x=1;x<=n;x++)kup.push_back({kompy[x][1],kompy[x][2]});
        kup.push_back({-1,1e9});
        sort(kup.begin(),kup.end(),greater<pair<ll,ll>>());
        for (int x=1;x<=m;x++)oso.push_back({osoby[x][1],osoby[x][2]});
        sort(oso.begin(),oso.end());
        mozl.push(-2e9);
        int p=0;
        ll odp=0;
        for (int x=m;x>=1;x--){
            while(kup[p].first>=oso[x].first){
                mozl.push(-kup[p].first);
                p++;
            }
            if (-mozl.top()<oso[x].second){
                odp += oso[x].second+mozl.top(); mozl.pop();
                mozl.push(-oso[x].second);
            }
        }
        cout << odp << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...