답안 #830218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830218 2023-08-19T00:03:05 Z OAleksa 쌀 창고 (IOI11_ricehub) C++14
100 / 100
16 ms 2796 KB
#include <bits/stdc++.h>
#include "ricehub.h"
#define f first
#define s second
using namespace std; 
 
int besthub(int R, int L, int X[], long long B)
{
  	int n = R;
  	int a[n];
  	for(int i = 0;i < n;i++)
  		a[i] = X[i];
  	vector<long long> p(n);
  	p[0] = a[0];
  	for(int i = 1;i < n;i++)
  		p[i] = p[i - 1] + a[i];
  	auto check = [&](int l, int r) {
  		int mid = (l + r) / 2;
  		long long sl = 1ll * a[mid] * (mid - l + 1) - p[mid] + (l == 0 ? 0 : p[l - 1]);
  		long long sr = 1ll * p[r] - p[mid] - 1ll * a[mid] * (r - mid);
  		return sl + sr <= B;
  	};
  	int ans = 1;
	for(int i = 0;i < n;i++) {
		int l = i, r = n - 1, mx = i;
		while(l <= r) {
			int mid = (l + r) / 2;
			if(check(i, mid)) {
				mx = mid;
				l = mid + 1;
			}
			else
				r = mid - 1;
		}
		ans = max(ans, mx - i + 1);
	}
	return ans;
}
 
// signed main()
// {
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
	// cout.tie(0);
	// int tt = 1;
	// //cin >> tt;
	// while(tt--) {
		 // int n, k;
		 // long long x;
		 // cin >> n >> k >> x;
		 // int a[n];
		 // for(int i = 0;i < n;i++)
		 	// cin >> a[i];
		// cout << besthub(n, k, a, x);
	// }
   // return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 0 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 0 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 0 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 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 1 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 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 0 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 0 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 340 KB Output is correct
26 Correct 1 ms 340 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 3 ms 596 KB Output is correct
3 Correct 13 ms 1876 KB Output is correct
4 Correct 13 ms 1828 KB Output is correct
5 Correct 6 ms 980 KB Output is correct
6 Correct 6 ms 980 KB Output is correct
7 Correct 13 ms 1876 KB Output is correct
8 Correct 12 ms 1868 KB Output is correct
9 Correct 7 ms 1088 KB Output is correct
10 Correct 7 ms 980 KB Output is correct
11 Correct 16 ms 1780 KB Output is correct
12 Correct 13 ms 1876 KB Output is correct
13 Correct 6 ms 1476 KB Output is correct
14 Correct 7 ms 1492 KB Output is correct
15 Correct 12 ms 2144 KB Output is correct
16 Correct 10 ms 2264 KB Output is correct
17 Correct 12 ms 2608 KB Output is correct
18 Correct 12 ms 2644 KB Output is correct
19 Correct 14 ms 2796 KB Output is correct
20 Correct 13 ms 2772 KB Output is correct