답안 #251998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251998 2020-07-23T14:31:10 Z aZvezda 학교 설립 (IZhO13_school) C++14
0 / 100
228 ms 23788 KB
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e7 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const ll MAX_N = 3e5 + 10;
bool used[MAX_N];
pair<ll, pair<ll, ll> > toSrt[MAX_N];

struct HeapSum {
    ll sum = 0, limit = -1;
    priority_queue<ll> pq;
    HeapSum() {}
    HeapSum(ll _limit) : limit(_limit) {}
    void push(ll x) {
        pq.push(-x);
        sum += x;
        if(pq.size() > limit) {
            sum += pq.top();
            pq.pop();
        }
    }
    ll ans() {
        if(pq.size() != limit) {
            return -mod * mod;
        } else {
            return sum;
        }
    }
};

ll pref[MAX_N], suf[MAX_N];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, m, s;
    cin >> n >> m >> s;
    for(ll i = 0; i < n; i ++) {
        ll a, b;
        cin >> a >> b;
        toSrt[i] = {b - a, {a, b}};
    }
    sort(toSrt, toSrt + n);
    HeapSum music(m), sport(s);
    pref[0] = -mod * mod;
    if(m == 0) {pref[0] = 0;}
    for(ll i = 0; i < n; i ++) {
        music.push(toSrt[i].second.first);
        pref[i + 1] = music.ans();
    }
    ll ret = 0;
    suf[n] = -mod * mod;
    if(s == 0) {suf[n] = 0;}
    for(ll i = n - 1; i >= 0; i --) {
        sport.push(toSrt[i].second.second);
        suf[i] = sport.ans();
    }
    for(ll i = 0; i <= n; i ++) {
        cout << i << " " << pref[i] << " " << suf[i] << endl;
        chkmax(ret, pref[i] +  suf[i]);
    }
    cout << ret << endl;
    return 0;
}


Compilation message

school.cpp: In member function 'void HeapSum::push(ll)':
school.cpp:28:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(pq.size() > limit) {
            ~~~~~~~~~~^~~~~~~
school.cpp: In member function 'll HeapSum::ans()':
school.cpp:34:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(pq.size() != limit) {
            ~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Incorrect 3 ms 640 KB Output isn't correct
8 Incorrect 3 ms 768 KB Output isn't correct
9 Incorrect 4 ms 768 KB Output isn't correct
10 Incorrect 3 ms 768 KB Output isn't correct
11 Incorrect 3 ms 768 KB Output isn't correct
12 Incorrect 4 ms 768 KB Output isn't correct
13 Incorrect 24 ms 3328 KB Output isn't correct
14 Incorrect 57 ms 6004 KB Output isn't correct
15 Incorrect 111 ms 10616 KB Output isn't correct
16 Incorrect 128 ms 14952 KB Output isn't correct
17 Incorrect 169 ms 17976 KB Output isn't correct
18 Incorrect 181 ms 19176 KB Output isn't correct
19 Incorrect 195 ms 20848 KB Output isn't correct
20 Incorrect 228 ms 23788 KB Output isn't correct