Submission #584239

# Submission time Handle Problem Language Result Execution time Memory
584239 2022-06-27T05:14:07 Z amunduzbaev Necklace (Subtask 1-3) (BOI19_necklace1) C++17
0 / 85
117 ms 111436 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], dp;
int dd[N][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];
		dp |= (dp << b[i]);
	}
	
	tp[0][0] = 1;
	for(int i=l;i<m;i++){
		int v = b[i];
		for(int j=i-l+1;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] = 0;
			else dd[j][k] = dd[j][k + 1] + 1;
		}
	}
	
	int res = 1e9, c = 0;
	
	while(c <= m - l){
		for(int j=k * n;j<=tot;j++){
			if(dp[j]){
				res = min(res, dd[c][max(0, sum - j)]);
			}
		}
		
		c++;
		if(k) k--;
	}
	
	if(res == 1e9) cout<<"impossible\n";
	else cout<<res<<"\n";
}

# Verdict Execution time Memory Grader output
1 Incorrect 117 ms 111436 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 117 ms 111436 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 117 ms 111436 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -