Submission #132697

# Submission time Handle Problem Language Result Execution time Memory
132697 2019-07-19T11:07:40 Z Vardanyan Hotel (CEOI11_hot) C++14
100 / 100
1644 ms 81176 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 500*1000+5;
long long c[N],p[N];
long long v[N],d[N];
bool cmp(pair<long long, long long> a, pair<long long,long> b){
    if(a.first>b.first) return a.first>b.first;
    if(a.first<b.first) return a.first>b.first;
    return a.second<b.second;
}
int main(){
    ios_base::sync_with_stdio(false);
    int n,m,k;
    cin>>n>>m>>k;
    multiset<pair<long long,long long> > ms;
    for(int i = 1;i<=n;i++){
        cin>>c[i]>>p[i];
        ms.insert({p[i],c[i]});
    }
    vector<pair<long long,long long> > all;
    for(int i = 1;i<=m;i++){
        cin>>v[i]>>d[i];
        all.push_back({v[i],d[i]});
    }
    sort(all.begin(),all.end(),cmp);
    int qn = k;
    long long ans = 0;
    vector<long long > pr;
    for(int i = 0;i<all.size();i++){
        if(!qn) break;
        long long x = all[i].second;
        if(ms.lower_bound({x,0}) == ms.end()) continue;
        pair<long long,long long> u = *ms.lower_bound({x,0});
        if(u.first>=x){
          if(all[i].first-u.second>0){
             //   ans-=u.second;
             //   ans+=all[i].first;
                ms.erase(ms.find(u));
               // qn--;
                pr.push_back(all[i].first-u.second);
            }
        }
    }
    sort(pr.rbegin(),pr.rend());
    for(int i = 0;i<pr.size();i++){
        if(!qn) break;
        qn--;
        ans+=pr[i];
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

hot.cpp: In function 'int main()':
hot.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<all.size();i++){
                   ~^~~~~~~~~~~
hot.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<pr.size();i++){
                   ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 6924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 11756 KB Output is correct
2 Correct 93 ms 9204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 434 ms 30388 KB Output is correct
2 Correct 208 ms 19460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 999 ms 55332 KB Output is correct
2 Correct 1112 ms 60108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1144 ms 67120 KB Output is correct
2 Correct 1320 ms 81176 KB Output is correct
3 Correct 1644 ms 79788 KB Output is correct