Submission #341705

# Submission time Handle Problem Language Result Execution time Memory
341705 2020-12-30T13:34:28 Z IZhO_2021_I_want_Silver Schools (IZhO13_school) C++14
5 / 100
560 ms 85120 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>-

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
#define int ll
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"

const int N = 2e5 + 5;
const int oo = 1e9 + 5;

int n, m, s, a[2][N], cur[2];
vector < pair <int, pii> > vec;
multiset <pii> other[2];
stack < pair <int, pii> > q[2];
bool used[N];

void add(int typ, int ind) {
    int val = a[typ][ind];
    --cur[typ];
    q[typ].push({a[typ][ind], {typ, ind}});
    used[ind] = 1;
    other[typ].erase(other[typ].find({val, ind}));
}

void del(int typ, int ind) {
    int val = a[typ][ind];
    ++cur[typ];
    used[ind] = 0;
    other[typ].insert({val, ind});
}

void solve() {
    cin >> n >> m >> s;
    for (int i = 1; i <= n; ++i) {
        cin >> a[0][i] >> a[1][i];

        vec.pb({a[0][i], {0, i}});
        vec.pb({a[1][i], {1, i}});

        other[0].insert({a[0][i], i});
        other[1].insert({a[1][i], i});
    }
    sort(all(vec));
    cur[0] = m, cur[1] = s;
    int sum = 0;
    for (int i = sz(vec)-1; i >= 0; --i) {
        int val = vec[i].F,
            typ = vec[i].S.F,
            ind = vec[i].S.S;
        int before_sum = sum;

        bool del_q = 0;
        if (!cur[typ]) {
            if (sz(q[typ])) { sum -= q[typ].top().F; del_q = 1; }
            else { continue; }
        }
        bool del_ind = 0, got_other = 0;
        if (used[ind]) {
            sum -= a[(typ^1)][ind]; del_ind = 1;
            if (sz(other[(typ^1)])) { sum += other[(typ^1)].rbegin() -> F; got_other = 1; }
        }
        sum += val;

        if (sum > before_sum) {
            add(typ, ind);
            if (del_q) { del(q[typ].top().S.F, q[typ].top().S.F); q[typ].pop(); }
            if (del_ind) { del(typ^1, ind); }
            if (got_other) { add(typ^1, other[(typ^1)].rbegin() -> S); }
        }
        else {
            sum = before_sum;
        }
    }
    cout << sum;
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
    Just Chalish!
*/

Compilation message

school.cpp:107:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  107 |  main () {
      |        ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Incorrect 5 ms 1388 KB Output isn't correct
8 Incorrect 5 ms 1388 KB Output isn't correct
9 Incorrect 5 ms 1448 KB Output isn't correct
10 Incorrect 7 ms 1516 KB Output isn't correct
11 Incorrect 6 ms 1448 KB Output isn't correct
12 Incorrect 8 ms 1448 KB Output isn't correct
13 Incorrect 58 ms 8480 KB Output isn't correct
14 Incorrect 150 ms 16712 KB Output isn't correct
15 Incorrect 370 ms 32928 KB Output isn't correct
16 Incorrect 512 ms 41264 KB Output isn't correct
17 Incorrect 514 ms 42368 KB Output isn't correct
18 Runtime error 495 ms 80456 KB Execution killed with signal 6 (could be triggered by violating memory limits)
19 Runtime error 560 ms 85120 KB Execution killed with signal 6 (could be triggered by violating memory limits)
20 Runtime error 530 ms 81280 KB Execution killed with signal 6 (could be triggered by violating memory limits)