Submission #676387

#TimeUsernameProblemLanguageResultExecution timeMemory
676387hgglmaoSchools (IZhO13_school)C++17
100 / 100
176 ms12896 KiB
#include <bits/stdc++.h>

#define fw(i, a, b, c) for (int i = a; i <= b; i += c)
#define bw(i, a, b, c) for (int i = a; i >= b; i -= c)
#define fauto(i, s) for (auto i : s)
#define exc(x) while (x--)

#define fi first
#define se second
#define mpr make_pair

#define pb push_back
#define pf push_front
#define emp emplace
#define eb emplace_back
#define ef emplace_front
#define pob pop_back
#define pof pop_front

#define lb lower_bound
#define ub upper_bound

#define str string
#define vct vector
#define qu queue
#define dq deque
#define pq priority_queue

#define TASK_NAME "test"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

// Quickread function
template <class _var>
void quickread(_var &cur_)
{
        // Interger values only
        char _ch = 0;
        _var _qr = 0;

        while (1)
        {
                _ch = getchar();
                if (_ch < '0' || _ch > '9')
                        break;

                _qr = _qr * 10 + _ch - '0';
        }

        cur_ = _qr;
}

const int MAX4 = 1e4 + 10;
const int MAX5 = 1e5 + 10;
const int MAX6 = 1e6 + 10;
const int MAX7 = 1e7 + 10;

const int MOD = 1e9 + 7; // Varies with task
const int HASH_BASE = 31;
const int PERM_HASH_BASE = 1e6 + 10; // Varies with variable limit

const int csMAX = 0;

class study
{
public:
        int field[2];
        study() { field[0] = field[1] = 0; }
        study(const int &f1, const int &f2)
        {
                field[0] = f1;
                field[1] = f2;
        }

        bool operator<(const study &SE)
        {
                return field[0] - field[1] > SE.field[0] - SE.field[1];
        }
        int operator[](const int &EX) { return field[EX]; }
} a[3 * MAX5], req;

int testcases = 1;
// Variable declarations
int n;
int SIGN[] = {1, -1};
ll maxStudy[3 * MAX5][2], totalStudy;
multiset<int> STO;

// Sub-functions
void GetMaxInRange(int x);

// Main-functions
void solve_main();
void result_export();
void debug_export();
void get_input();
void pretestcases();

void testgen()
{
        freopen(TASK_NAME ".inp", "w", stdout);
        srand(time(0));
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);

        // testgen(); return 0;

        if (fopen(TASK_NAME ".inp", "r"))
        {
                freopen(TASK_NAME ".inp", "r", stdin);
                freopen(TASK_NAME ".out", "w", stdout);
        }

        // pretestcases();
        // quickread(testcases);
        // cin >> testcases;
        exc(testcases)
        {
                get_input();

                solve_main();

                // debug_export();
                result_export();
                cout << '\n';
        }
}

void get_input()
{
        cin >> n >> req.field[0] >> req.field[1];
        fw(i, 1, n, 1)
        {
                cin >> a[i].field[0] >> a[i].field[1];
        }
}

void solve_main()
{
        sort(a + 1, a + n + 1);
        GetMaxInRange(0);
        GetMaxInRange(1);

        fw(i, 1, n, 1)
        {
                totalStudy = max(totalStudy, maxStudy[i][0] + maxStudy[i + 1][1]);
        }
}

void result_export()
{
        cout << totalStudy;
}

void GetMaxInRange(int x)
{
        int idStart = 1, idEnd = n;
        if (x)
                swap(idStart, idEnd);
        STO.clear();
        ll maxSum = 0;

        for(int i = idStart; SIGN[x] * i <= SIGN[x] * idEnd; i += SIGN[x])
        {
                maxSum += a[i][x];
                STO.insert(a[i][x]);

                if (STO.size() > req[x])
                {
                        maxSum -= *STO.begin();
                        STO.erase(STO.begin());
                }

                maxStudy[i][x] = maxSum;
        }
}

Compilation message (stderr)

school.cpp: In function 'void GetMaxInRange(int)':
school.cpp:180:32: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  180 |                 if (STO.size() > req[x])
      |                     ~~~~~~~~~~~^~~~~~~~
school.cpp: In function 'void testgen()':
school.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen(TASK_NAME ".inp", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp: In function 'int main()':
school.cpp:122:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |                 freopen(TASK_NAME ".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:123:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |                 freopen(TASK_NAME ".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...