답안 #741142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741142 2023-05-13T15:53:17 Z LCJLY 쌀 창고 (IOI11_ricehub) C++14
100 / 100
12 ms 2264 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

int besthub(int R, int L, int X[], long long B)
{
	int n=R,k=L;
	long long arr[n+5];
	for(int x=0;x<n;x++){
		arr[x+1]=X[x];
	}	
	
	long long psum[n+5];
	for(int x=1;x<=n;x++){
		psum[x]=psum[x-1]+arr[x];
	}
	
	long long l=1;
	int ans=0;
	
	for(long long x=1;x<=n;x++){
		while(l<x){
			long long mid=(l+x)/2;
			long long cost=arr[mid]*(mid-l)-(psum[mid-1]-psum[l-1])+(psum[x]-psum[mid])-arr[mid]*(x-mid);
			
			if(cost>B){
				l++;
			}
			else{
				break;
			}
		}
		ans=max(ans,(int)x-(int)l+1);
	}
	
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:8:10: warning: unused variable 'k' [-Wunused-variable]
    8 |  int n=R,k=L;
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 0 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 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 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 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 388 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 11 ms 2260 KB Output is correct
4 Correct 11 ms 2264 KB Output is correct
5 Correct 5 ms 1236 KB Output is correct
6 Correct 5 ms 1236 KB Output is correct
7 Correct 10 ms 2188 KB Output is correct
8 Correct 10 ms 2216 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 12 ms 2244 KB Output is correct
12 Correct 11 ms 2204 KB Output is correct
13 Correct 6 ms 1192 KB Output is correct
14 Correct 5 ms 1284 KB Output is correct
15 Correct 9 ms 1712 KB Output is correct
16 Correct 9 ms 1748 KB Output is correct
17 Correct 11 ms 2004 KB Output is correct
18 Correct 12 ms 2004 KB Output is correct
19 Correct 11 ms 2080 KB Output is correct
20 Correct 10 ms 2132 KB Output is correct