Submission #512858

# Submission time Handle Problem Language Result Execution time Memory
512858 2022-01-16T19:04:02 Z blue Hotel (CEOI11_hot) C++17
Compilation error
0 ms 0 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 == 1)
        // {
        //     // cerr << "B\n";
        //     if(spare)
        //     {
        //         fake.insert(x.v);
        //         spare--;
        //         // cerr << "inserting fake room of cost " << x.v << '\n';
        //     }
        //     else
        //     {
        //         fake.insert(x.v);
        //
        //         if(actual.empty() || *actual.begin() > *fake.begin())
        //             fake.erase(fake.begin());
        //         else
        //             actual.erase(actual.begin());
        //     }
        // }
        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';
}
#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 == 1)
        // {
        //     // cerr << "B\n";
        //     if(spare)
        //     {
        //         fake.insert(x.v);
        //         spare--;
        //         // cerr << "inserting fake room of cost " << x.v << '\n';
        //     }
        //     else
        //     {
        //         fake.insert(x.v);
        //
        //         if(actual.empty() || *actual.begin() > *fake.begin())
        //             fake.erase(fake.begin());
        //         else
        //             actual.erase(actual.begin());
        //     }
        // }
        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';
}

Compilation message

hot.cpp:148:8: error: redefinition of 'struct obj'
  148 | struct obj
      |        ^~~
hot.cpp:10:8: note: previous definition of 'struct obj'
   10 | struct obj
      |        ^~~
hot.cpp:155:6: error: redefinition of 'bool operator<(obj, obj)'
  155 | bool operator < (obj A, obj B)
      |      ^~~~~~~~
hot.cpp:17:6: note: 'bool operator<(obj, obj)' previously defined here
   17 | bool operator < (obj A, obj B)
      |      ^~~~~~~~
hot.cpp:161:5: error: redefinition of 'int main()'
  161 | int main()
      |     ^~~~
hot.cpp:23:5: note: 'int main()' previously defined here
   23 | int main()
      |     ^~~~