Submission #632194

# Submission time Handle Problem Language Result Execution time Memory
632194 2022-08-19T15:49:51 Z PoonYaPat Rice Hub (IOI11_ricehub) C++14
100 / 100
44 ms 6456 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

multiset<int> rsq,lsq;
int median=INT_MAX,ans;
ll rsum,lsum;

void med() {
    if (lsq.size()<rsq.size()) {
        auto it=rsq.begin();
        rsum-=*it;
        lsum+=*it;
        lsq.insert(*it);
        rsq.erase(it);
    }

    if (lsq.size()>rsq.size()+1) {
        auto it=lsq.end(); --it;
        rsum+=*it;
        lsum-=*it;
        rsq.insert(*it);
        lsq.erase(it);
    }

    auto it=lsq.end();
    median=*(--it);
}

void add(int x) {
    if (x<=median) lsum+=x, lsq.insert(x);
    else rsum+=x, rsq.insert(x);
    med();
}

void del(int x) {
    if (x<=median) {
        auto it=lsq.find(x);
        lsum-=x;
        lsq.erase(it);
    } else {
        auto it=rsq.find(x);
        rsum-=x;
        rsq.erase(it);
    }
    med();
}


int besthub(int n, int l, int c[], long long b) {
    int i=0, j=0;
    ll x=0;

    while (i<n) {
        add(c[i++]);

        if (lsq.size()==rsq.size()) x=rsum-lsum;
        else x=rsum-lsum+median;

        while (x>b && j<n) {
            del(c[j++]);
            if (lsq.size()==rsq.size()) x=rsum-lsum;
            else x=rsum-lsum+median;
        }

        ans=max(ans,i-j);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 260 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 580 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 580 KB Output is correct
27 Correct 2 ms 448 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 452 KB Output is correct
2 Correct 5 ms 428 KB Output is correct
3 Correct 36 ms 6388 KB Output is correct
4 Correct 36 ms 6456 KB Output is correct
5 Correct 13 ms 852 KB Output is correct
6 Correct 14 ms 808 KB Output is correct
7 Correct 36 ms 6208 KB Output is correct
8 Correct 33 ms 6092 KB Output is correct
9 Correct 17 ms 980 KB Output is correct
10 Correct 19 ms 1072 KB Output is correct
11 Correct 36 ms 6392 KB Output is correct
12 Correct 35 ms 6368 KB Output is correct
13 Correct 14 ms 852 KB Output is correct
14 Correct 14 ms 916 KB Output is correct
15 Correct 25 ms 4776 KB Output is correct
16 Correct 38 ms 4812 KB Output is correct
17 Correct 43 ms 5768 KB Output is correct
18 Correct 44 ms 5708 KB Output is correct
19 Correct 34 ms 6020 KB Output is correct
20 Correct 33 ms 6112 KB Output is correct