Submission #910616

# Submission time Handle Problem Language Result Execution time Memory
910616 2024-01-18T06:22:24 Z GrandTiger1729 Hotel (CEOI11_hot) C++17
100 / 100
343 ms 29700 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, m, K;
    cin >> n >> m >> K;
    vector<pair<int, int>> a(n), b(m);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].second >> a[i].first;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b[i].second >> b[i].first;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    priority_queue<int> pq;
    priority_queue<int, vector<int>, greater<>> res;
    int j = 0;
    for (int i = 0; i < n; i++)
    {
        while (j < m && b[j].first <= a[i].first)
        {
            pq.push(b[j++].second);
        }
        if (pq.size())
        {
            res.push(pq.top() - a[i].second);
            pq.pop();
        }
        while (res.size() > K)
        {
            res.pop();
        }
    }
    long long ans = 0;
    while (res.size())
    {
        ans += max(0, res.top());
        res.pop();
    }
    cout << ans << '\n';
    return 0;
}

Compilation message

hot.cpp: In function 'int main()':
hot.cpp:34:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<void> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         while (res.size() > K)
      |                ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 4884 KB Output is correct
2 Correct 29 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 12348 KB Output is correct
2 Correct 75 ms 6716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 248 ms 22376 KB Output is correct
2 Correct 248 ms 22744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 24832 KB Output is correct
2 Correct 343 ms 29700 KB Output is correct
3 Correct 316 ms 26684 KB Output is correct