Submission #207782

# Submission time Handle Problem Language Result Execution time Memory
207782 2020-03-09T00:11:03 Z peuch Rice Hub (IOI11_ricehub) C++17
100 / 100
24 ms 2296 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 2000000;
long long sumD[MAXN], sumE[MAXN];

bool test(long long ini, long long fim, int R, long long B, int X[]);

int besthub(int R, int L, int X[], long long B)
{	
    	long long ans = 0;
        sumD[0] = X[0]; 
        sumE[R - 1] = 0;
    	for(int i = R - 2; i >= 0; i--)
    		sumE[i] = sumE[i + 1] + X[R - 1] - X[i];
    	for(int i = 1; i < R; i++)
    		sumD[i] = sumD[i - 1] + X[i];
    	for(long long ini = 0, fim = 0; ini < R; ini++){
    		while(test(ini, fim, R, B, X) && fim < R) fim++;
    		ans = max(fim - ini, ans);
    	}
    	return (int)ans;
}

bool test(long long ini, long long fim, int R, long long B, int X[]){
    long long m = (ini + fim) >> 1;
    long long left = sumE[ini] - sumE[m] - (m - ini) * (X[R - 1] - X[m]);
    long long right = sumD[fim] - sumD[m] - (fim - m) * X[m];
  	return left + right <= B;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 300 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 504 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 6 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 760 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
3 Correct 21 ms 2296 KB Output is correct
4 Correct 21 ms 2296 KB Output is correct
5 Correct 11 ms 1400 KB Output is correct
6 Correct 11 ms 1272 KB Output is correct
7 Correct 19 ms 2296 KB Output is correct
8 Correct 21 ms 2296 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
10 Correct 12 ms 1272 KB Output is correct
11 Correct 24 ms 2296 KB Output is correct
12 Correct 23 ms 2296 KB Output is correct
13 Correct 12 ms 1272 KB Output is correct
14 Correct 12 ms 1272 KB Output is correct
15 Correct 18 ms 1784 KB Output is correct
16 Correct 20 ms 1784 KB Output is correct
17 Correct 21 ms 2040 KB Output is correct
18 Correct 22 ms 2040 KB Output is correct
19 Correct 22 ms 2168 KB Output is correct
20 Correct 22 ms 2168 KB Output is correct