답안 #584231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584231 2022-06-27T04:54:33 Z amunduzbaev Kitchen (BOI19_kitchen) C++17
0 / 100
142 ms 112748 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
//~ #define int ll

const int N = 305;
int a[N], b[N];
bitset<N * N> tp[N];
int dd[N][N * N];
int dp[N * N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m, k; cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i] < k){
			cout<<"impossible\n";
			return 0;
		}
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	
	int sum = accumulate(a, a + n, 0);
	sort(b, b + m);
	int l = m, tot = 0;
	dp[0] = 1;
	for(int i=0;i<m;i++){
		if(b[i] > n) { l = i; break; }
		tot += b[i];
		for(int j = tot;j >= b[i];j--){
			dp[j] |= dp[j - b[i]];
		}
	}
	
	tp[0][0] = 1;
	for(int i=l;i<m;i++){
		int v = b[i] - n;
		for(int j=m-l;j>0;j--){
			tp[j] |= (tp[j - 1] << v);
		}
	}
	
	
	
	for(int j=0;j<N;j++){
		dd[j][N * N - 1] = 1e9;
		for(int k=N * N - 2;~k;k--){
			if(tp[j][k]) dd[j][k] = k;
			else dd[j][k] = dd[j][k + 1];
		}
	}
	
	int res = 1e9, c = 0;
	while(c <= m - l && sum >= 0){
		for(int j=k * n;j<=tot;j++){
			if(dp[j]){
				res = min(res, j + dd[c][sum - j] - sum);
			}
		}
		
		//~ cout<<c<<" "<<res<<"\n";
		sum -= n, c++;
		if(k) k--;
	}
	
	if(res == 1e9) cout<<"impossible\n";
	else cout<<res<<"\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 111308 KB Output is correct
2 Correct 117 ms 111312 KB Output is correct
3 Correct 106 ms 111328 KB Output is correct
4 Correct 102 ms 111340 KB Output is correct
5 Correct 105 ms 111300 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 111308 KB Output is correct
2 Correct 117 ms 111312 KB Output is correct
3 Correct 106 ms 111328 KB Output is correct
4 Correct 102 ms 111340 KB Output is correct
5 Correct 105 ms 111300 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 111596 KB Output is correct
2 Correct 110 ms 111484 KB Output is correct
3 Correct 116 ms 111644 KB Output is correct
4 Correct 142 ms 112748 KB Output is correct
5 Incorrect 120 ms 111712 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 111732 KB Output is correct
2 Correct 105 ms 111588 KB Output is correct
3 Correct 110 ms 111328 KB Output is correct
4 Correct 102 ms 111344 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 111308 KB Output is correct
2 Correct 117 ms 111312 KB Output is correct
3 Correct 106 ms 111328 KB Output is correct
4 Correct 102 ms 111340 KB Output is correct
5 Correct 105 ms 111300 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -