답안 #346314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
346314 2021-01-09T10:07:50 Z Mefarnis 쌀 창고 (IOI11_ricehub) C++14
100 / 100
17 ms 2588 KB
#include <algorithm>
#include "ricehub.h"
using namespace std;

long long getCost(int l , int r , int x[], long long sum[]) {
	int m = (l+r) >> 1;
	long long cost = 0;
	if(l < m)
		cost += (m-l) * (long long) x[m-1] - (sum[m-1] - sum[l-1]);
	if(m < r)
		cost += (sum[r] - sum[m]) - (r-m) * (long long) x[m-1];
	return cost;
}

int besthub(int n, int xmax, int x[], long long budget)
{
	int ans = 0;
	long long sum[n+1];
	sum[0] = 0;
	for( int i = 1 ; i <= n ; i++ )
		sum[i] = sum[i-1] + x[i-1];
	for( int l = 1 , r = 1 ; l <= n ; l++ ) {
		r = max(l,r);
		while(r < n && getCost(l,r+1,x,sum) <= budget)
			r++;
		ans = max(ans,r-l+1);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 268 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 0 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 17 ms 2588 KB Output is correct
4 Correct 17 ms 2540 KB Output is correct
5 Correct 7 ms 1260 KB Output is correct
6 Correct 8 ms 1260 KB Output is correct
7 Correct 15 ms 2284 KB Output is correct
8 Correct 15 ms 2284 KB Output is correct
9 Correct 7 ms 1152 KB Output is correct
10 Correct 7 ms 1132 KB Output is correct
11 Correct 17 ms 2540 KB Output is correct
12 Correct 17 ms 2540 KB Output is correct
13 Correct 8 ms 1260 KB Output is correct
14 Correct 8 ms 1260 KB Output is correct
15 Correct 13 ms 1900 KB Output is correct
16 Correct 13 ms 2028 KB Output is correct
17 Correct 15 ms 2284 KB Output is correct
18 Correct 15 ms 2284 KB Output is correct
19 Correct 16 ms 2412 KB Output is correct
20 Correct 16 ms 2412 KB Output is correct