Submission #468525

# Submission time Handle Problem Language Result Execution time Memory
468525 2021-08-28T15:59:04 Z mychecksedad Watching (JOI13_watching) C++17
50 / 100
32 ms 3372 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 110, MX = 1e9;

int n, p, q, arr[N], dp[N][N][N];
bool check(int w){
	for(int i = 0; i <= n+1; i++) for(int j = 0; j <= p+1; j++) for(int k = 0; k <= q+1; k++) dp[i][j][k] = -1;
	dp[0][0][0] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= p; j++){
			for(int k = 0; k <= q; k++){
				if(k==j&&k==0) continue;
				if(j > 0 && dp[i - 1][j - 1][k] > -1){
					dp[i][j][k] = max(dp[i][j][k], arr[i] + w);
				}
				if(k > 0 && dp[i - 1][j][k - 1] > -1){
					dp[i][j][k] = max(dp[i][j][k], arr[i] + 2*w);
				}
				if(dp[i - 1][j][k] > arr[i]) dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
				// cout << dp[i][j][k] << " . " << j << ' ' << k << " | "; 
			}

			// cout << '\n';
		}
		// cout << '\n';
	}
	// cout << '\n';
	return (dp[n][p][q] > -1); 
}


int main(){
	cin >> n >> p >> q;
	for(int i = 1; i <= n; i++) cin >> arr[i];
	if(p + q >= n){
		cout << 1;
		return 0;
	}
	sort(arr+1, arr+n+1);
	int l = 1, h = MX, ans = MX;
	while(l <= h){
		int mid = ((l+h)>>1);
		if(check(mid)){
			ans = min(ans, mid);
			h = mid - 1;
		}else
			l = mid + 1;
	}
	cout << ans;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 2 ms 972 KB Output is correct
9 Correct 2 ms 1228 KB Output is correct
10 Correct 12 ms 1436 KB Output is correct
11 Correct 17 ms 3372 KB Output is correct
12 Correct 32 ms 2892 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 396 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -