Submission #289466

# Submission time Handle Problem Language Result Execution time Memory
289466 2020-09-02T16:44:47 Z BeanZ Rice Hub (IOI11_ricehub) C++14
49 / 100
22 ms 1736 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
int besthub(int r, int l, int x[], ll b){
        ll lf = 1, rt = 1;
        ll cur = 0, ans = 0;
        while (rt < r && (cur + (x[rt] - x[0])) <= b){
                cur = cur + (x[rt] - x[0]);
                rt++;
        }
        ans = max(ans, rt - lf + 1);
        //cout << cur << " " << lf << " " << rt << endl;
        for (int i = 2; i <= r; i++){
                cur = cur - (rt - i + 1) * (x[i - 1] - x[i - 2]);
                cur = cur + (i - lf) * (x[i - 1] - x[i - 2]);
                while (cur > b){
                        cur = cur - (x[i - 1] - x[lf - 1]);
                        lf++;
                }
                //cout << cur << " " << lf << " " << rt << endl;// << " " << cur + x[i - 1] - x[lf - 2] << " " << i << " " << x[i - 1] << endl;
                //cout << get(lf, rt, i) << endl;
                //cout << (x[i - 1] - x[lf - 2]) << " " << (x[rt - 1] - x[i - 1]) << " " << i << " " << lf << " " << rt << endl;
                while (rt < r && (x[rt] - x[i - 1]) < (x[i - 1] - x[lf - 1])){
                        cur = cur + x[rt] - x[i - 1] - (x[i - 1] - x[lf - 1]);
                        rt++;
                        lf++;
                }
                while (lf > 1 && ((x[i - 1] - x[lf - 2]) < (x[rt - 1] - x[i - 1]))){
                        cur = cur + x[i - 1] - x[lf - 2] - (x[rt - 1] - x[i - 1]);
                        rt--;
                        lf--;
                }
                while (rt < r && (cur + x[rt] - x[i - 1]) <= b){
                        cur = cur + x[rt] - x[i - 1];
                        rt++;
                }
                //cout << cur << " " << lf << " " << rt << endl;
                //cout << get(lf, rt, i) << endl;
                ans = max(ans, rt - lf + 1);
        }
        return ans;
}
/*
ll x[N], sum[N];
ll get(ll l, ll r, ll mid){
        return (mid - l) * x[mid - 1] - (sum[mid - 1] - sum[l - 1]) + (sum[r] - sum[mid]) - (r - mid) * x[mid - 1];
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("time.in", "r")){
                freopen("time.in", "r", stdin);
                freopen("time.out", "w", stdout);
        }
        ll r, l, b;
        cin >> r >> l >> b;
        for (int i = 1; i <= r; i++) cin >> x[i - 1], sum[i] = sum[i - 1] + x[i - 1];
        ll lf = 1, rt = 1;
        ll cur = 0, ans = 0;
        while (rt < r && (cur + (x[rt] - x[0])) <= b){
                cur = cur + (x[rt] - x[0]);
                rt++;
        }
        ans = max(ans, rt - lf + 1);
        //cout << cur << " " << lf << " " << rt << endl;
        for (int i = 2; i <= r; i++){
                cur = cur - (rt - i + 1) * (x[i - 1] - x[i - 2]);
                cur = cur + (i - lf) * (x[i - 1] - x[i - 2]);
                while (cur > b){
                        cur = cur - (x[i - 1] - x[lf - 1]);
                        lf++;
                }
                //cout << cur << " " << lf << " " << rt << endl;// << " " << cur + x[i - 1] - x[lf - 2] << " " << i << " " << x[i - 1] << endl;
                //cout << get(lf, rt, i) << endl;
                //cout << (x[i - 1] - x[lf - 2]) << " " << (x[rt - 1] - x[i - 1]) << " " << i << " " << lf << " " << rt << endl;
                while (rt < r && (x[rt] - x[i - 1]) < (x[i - 1] - x[lf - 1])){
                        cur = cur + x[rt] - x[i - 1] - (x[i - 1] - x[lf - 1]);
                        rt++;
                        lf++;
                }
                while (lf > 1 && ((x[i - 1] - x[lf - 2]) < (x[rt - 1] - x[i - 1]))){
                        cur = cur + x[i - 1] - x[lf - 2] - (x[rt - 1] - x[i - 1]);
                        rt--;
                        lf--;
                }
                while (rt < r && (cur + x[rt] - x[i - 1]) <= b){
                        cur = cur + x[rt] - x[i - 1];
                        rt++;
                }
                //cout << cur << " " << lf << " " << rt << endl;
                //cout << get(lf, rt, i) << endl;
                ans = max(ans, rt - lf + 1);
        }
        cout << ans;
}
/*
*/

Compilation message

ricehub.cpp:101:1: warning: "/*" within comment [-Wcomment]
  101 | /*
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Incorrect 0 ms 384 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 17 ms 1152 KB Output is correct
4 Correct 18 ms 1152 KB Output is correct
5 Correct 8 ms 896 KB Output is correct
6 Correct 8 ms 896 KB Output is correct
7 Correct 16 ms 1152 KB Output is correct
8 Correct 16 ms 1152 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 8 ms 768 KB Output is correct
11 Correct 21 ms 1144 KB Output is correct
12 Correct 21 ms 1152 KB Output is correct
13 Correct 9 ms 896 KB Output is correct
14 Correct 9 ms 896 KB Output is correct
15 Correct 22 ms 1408 KB Output is correct
16 Correct 15 ms 1408 KB Output is correct
17 Correct 17 ms 1664 KB Output is correct
18 Correct 18 ms 1664 KB Output is correct
19 Correct 18 ms 1664 KB Output is correct
20 Correct 19 ms 1736 KB Output is correct