Submission #530713

# Submission time Handle Problem Language Result Execution time Memory
530713 2022-02-26T14:19:57 Z peuch Hotel (CEOI11_hot) C++17
80 / 100
4000 ms 19904 KB

#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
 
vector<int> roomSize, roomCost;
vector<pii> offer;
 
int main(){
  int n, m, o; cin >> n >> m >> o;
  for(int i = 0;i<n;i++){
    int a, b; cin >> a >> b;
    roomCost.push_back(a); roomSize.push_back(b);
  }
  sort(roomCost.begin(),roomCost.end());
  sort(roomSize.begin(),roomSize.end());
  for(int i = 0;i<m;i++){
    int a, b; cin >> a >> b;
    offer.push_back(make_pair(a,b));
  }
  sort(offer.begin(),offer.end());
  long long int resp = 0;
  multiset<long long> moedas;
  for(int i = offer.size() - 1; i >= 0; i--){
    if(roomCost.empty()) break;
    // printf("processing offer (%d,%d)\n",offer[i].first, offer[i].second);
    auto it = lower_bound(roomSize.begin(), roomSize.end(), offer[i].second);
    if(it == roomSize.end()) continue;
    int roomId = it - roomSize.begin();
    if(offer[i].first - roomCost[roomId] > 0){
      // printf("-chose room %d (%d,%d) with %d profit\n",roomId, roomCost[roomId], roomSize[roomId], offer[i].first - roomCost[roomId]);
      resp += offer[i].first - roomCost[roomId];
      moedas.insert(offer[i].first - roomCost[roomId]);
      if(moedas.size() > o){
        resp -= *moedas.begin();
        moedas.erase(moedas.begin());
      }
      roomCost.erase(roomCost.begin() + roomId); roomSize.erase(roomSize.begin() + roomId);
    }
  }
  cout << resp << "\n";
  return 0;
}

Compilation message

hot.cpp: In function 'int main()':
hot.cpp:35:24: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |       if(moedas.size() > o){
      |          ~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 499 ms 6276 KB Output is correct
2 Correct 315 ms 3356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3542 ms 17576 KB Output is correct
2 Correct 1032 ms 6276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4080 ms 19904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4053 ms 19772 KB Time limit exceeded
2 Halted 0 ms 0 KB -