Submission #512826

# Submission time Handle Problem Language Result Execution time Memory
512826 2022-01-16T18:41:44 Z blue Hotel (CEOI11_hot) C++17
10 / 100
4000 ms 17812 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)
        {
            spare++;
            rooms_total += x.v;

            // cerr << "adding empty room of size " << x.s << '\n';
        }
        else if(x.t == 1)
        {
            if(spare)
            {
                fake.insert(x.v);
                spare--;
            }
            else
            {
                // fake.insert(x.v);
                //
                // if(actual.empty() || *actual.begin() > *fake.begin())
                //     fake.erase(fake.begin());
                // else
                //     actual.erase(actual.begin());

                if(actual.empty())
                {
                    if(fake.empty())
                    {
                        ;
                    }
                    else
                    {
                        int f = *fake.begin();
                        if(x.v < f) continue;
                        else
                        {
                            fake.erase(fake.begin());
                            fake.insert(x.v);
                        }
                    }
                }
                else
                {
                    if(fake.empty())
                    {
                        int a = *actual.begin();
                        if(x.v < a) continue;
                        else
                        {
                            actual.erase(actual.begin());
                            fake.insert(x.v);
                        }
                    }
                    else
                    {
                        int a = *actual.begin();
                        int f = *fake.begin();
                        if(a < f)
                        {
                            if(x.v <= a) continue;
                            else
                            {
                                actual.erase(actual.begin());
                                fake.insert(x.v);
                            }
                        }
                        else
                        {
                            if(x.v <= f) continue;
                            else
                            {
                                fake.erase(fake.begin());
                                fake.insert(x.v);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            if(spare)
            {
                spare--;
                if(sz(actual) < o)
                    actual.insert(x.v);
                else
                {
                    if(x.v <= *actual.begin()) continue;
                    else
                    {
                        actual.insert(x.v);
                        actual.erase(*actual.begin());
                    }
                }
            }
            else
            {
                if(sz(actual) == o)
                {
                    if(x.v <= *actual.begin()) continue;
                    else
                    {
                        actual.insert(x.v);
                        actual.erase(*actual.begin());
                    }
                }
                else
                {
                    actual.insert(x.v);
                    if(actual.empty() || *actual.begin() > *fake.begin())
                        fake.erase(fake.begin());
                    else
                        actual.erase(actual.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 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4048 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4051 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4051 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4074 ms 588 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 4094 ms 1612 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 4094 ms 2764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4065 ms 7364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 14412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4075 ms 17812 KB Time limit exceeded
2 Halted 0 ms 0 KB -