답안 #644455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644455 2022-09-24T17:10:26 Z amoorj Kitchen (BOI19_kitchen) C++17
0 / 100
35 ms 35208 KB
//#pragma GCC optimize ("O3,unroll-loops,Ofast")
//#pragma GCC target ("avx2,bmi,bmi2,popcnt")
#include <bits/stdc++.h>
#define F first
#define pb push_back
#define sz size()
#define S second
using namespace std;
typedef long long int ll;

const int N = 303;
int n,k,m,a[N],b[N],dp[N][N*N];
ll sum = 0;
bitset<N*N> dp2;

inline void init(){
}
inline void input(){
	cin >> n >> m >> k;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	for(int i=0;i<m;i++)
		cin >> b[i];
}
inline void solve(){
	dp2[0] = 1;
	for(int i=0;i<m;i++){
		dp2 |= (dp2 << b[i]);
		for(int j=0;j<N*N;j++){
			if(!dp2[j])
				continue;
			if(j >= b[i])
				dp[i+1][j] = max(dp[i][j], dp[i][j-b[i]] + min(b[i], n));
			else
				dp[i+1][j] = dp[i][j];
		}
	}
	bool ok = false;
	int ans = 1e9;
	for(int j=0;j<N*N;j++){
		if(dp2[j] && dp[m][j] >= n*k){
			ans = min(ans, j);
			ok = true;
		}
	}
	for(int i=0;i<n;i++){
		if(a[i] < k){
			cout << "Impossible";
			return;
		}
	}
	if(ok)
		cout << ans - sum;
	else
		cout << "Impossible";
}
int main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	init();
	int queries = 1;
//	cin >> queries;
	while(queries--){
		input();
		solve();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 35208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 636 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Incorrect 4 ms 596 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -