Submission #1017167

# Submission time Handle Problem Language Result Execution time Memory
1017167 2024-07-09T05:06:54 Z caterpillow Hotel (CEOI11_hot) C++17
100 / 100
1205 ms 70456 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end() 
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;

template<template<typename> class Container, typename T>
ostream& operator<<(ostream& os, Container<T> o) {
    os << "{"; 
    int g = size(o); 
    for (auto i : o) os << i << ((--g) == 0 ? "" : ", "); 
    os << "}";
    return os;
}

void _print() {
    cerr << "\n";
}

template<typename T, typename ...V>
void _print(T t, V... v) {
    cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);
}

#ifdef LOCAL
#define dbg(x...) cerr << #x << " = "; _print(x);
#else
#define dbg(x...)
#define cerr if (0) std::cerr
#endif

/*

isnt this just a greedy wtf

*/

main() {
    cin.tie(0)->sync_with_stdio(0);
    
    int n, m, o; cin >> n >> m >> o; 
    multiset<pl> hotels;
    F0R (i, n) {
        ll c, v; cin >> c >> v;
        hotels.insert({v, c});
    }
    using t3 = tuple<ll, pl, pl>;
    priority_queue<t3> pq;
    ll ans = 0;
    int taken = 0;
    auto add = [&] (ll v, ll c) {
        auto it = hotels.lower_bound({v, -1});
        if (it == hotels.end()) return;
        pq.push({c - it->s, {v, c}, *it});
    };
    F0R (i, m) {
        ll v, c; cin >> c >> v;
        add(v, c);
    }
    while (taken < o) {
        auto [profit, request, hotel] = pq.top(); pq.pop();
        if (profit <= 0) break;
        if (!hotels.count(hotel)) {
            add(request.f, request.s);
        } else {
            hotels.erase(hotels.find(hotel));
            ans += profit;
            taken++;
        }
    }
    cout << ans << endl;
}

Compilation message

hot.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 12740 KB Output is correct
2 Correct 58 ms 9176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 29360 KB Output is correct
2 Correct 94 ms 19736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 465 ms 58048 KB Output is correct
2 Correct 494 ms 59040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 65780 KB Output is correct
2 Correct 938 ms 70456 KB Output is correct
3 Correct 1205 ms 67832 KB Output is correct