Submission #512861

# Submission time Handle Problem Language Result Execution time Memory
512861 2022-01-16T19:04:45 Z blue Hotel (CEOI11_hot) C++17
10 / 100
440 ms 41340 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

using ll = long long;
#define sz(x) int(x.size())

struct obj
{
    int s;
    int v;
    int t;
};

bool operator < (obj A, obj B)
{
    if(A.s != B.s) return A.s > B.s;
    else return A.t > B.t;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m, o;
    cin >> n >> m >> o;

    vector<obj> a(m+2*n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i].v >> a[i].s;
        a[i].t = 2; //room
    }

    for(int i = n; i < 2*n; i++)
    {
        a[i] = a[i-n];
        a[i].t = 1;
    }

    for(int j = 2*n; j < 2*n+m; j++)
    {
        cin >> a[j].v >> a[j].s;
        a[j].t = 0; //customer
    }

    sort(a.begin(), a.end());

    ll rooms_total = 0;
    // int room_count = 0;
    int spare = 0;

    multiset<int> actual, fake;

    for(obj x: a)
    {
        if(x.t == 2)
        {
            // cerr << "A\n";
            spare++;
            rooms_total += x.v;

            if(spare)
            {
                fake.insert(x.v);
                spare--;
            }

            // cerr << "adding empty room of size " << x.s << '\n';
        }
        else if(x.t == 0)
        {
            // cerr << "C\n";
            if(spare)
            {
                // cerr << "C1\n";
                if(sz(actual) < o)
                {
                    actual.insert(x.v);
                    spare--;
                }
                else
                {
                    actual.insert(x.v);
                    actual.erase(*actual.begin());
                }
                // spare--;
            }
            else
            {
                // cerr << "C2\n";
                if(sz(actual) == o)
                {
                    // cerr << "#\n";
                    actual.insert(x.v);
                    actual.erase(*actual.begin());
                }
                else
                {
                    // cerr << "?\n";
                    actual.insert(x.v);
                    if(fake.empty() || *actual.begin() < *fake.begin())
                        actual.erase(actual.begin());
                    else
                        fake.erase(fake.begin());
                }
            }
        }
    }

    ll ans = -rooms_total;
    for(int a: actual) ans += a;
    for(int f: fake) ans += f;

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 976 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 3524 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 5972 KB Output is correct
2 Incorrect 51 ms 5636 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 16632 KB Output is correct
2 Incorrect 107 ms 9588 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 371 ms 33092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 440 ms 41340 KB Output isn't correct
2 Halted 0 ms 0 KB -