이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define nl "\n"
#define yes "YES"
#define no "NO"
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const ll N=301;
ll n,m,k;
vector<ll>a,b;
ll dp[N*N*N+10];
int main() {
fast
memset(dp,-1, sizeof(dp));
cin>>n>>m>>k;
a=vector<ll>(n);
b=vector<ll>(m);
ll sm=0;
bool ok=1;
for(ll &i:a)cin>>i,sm+=i,ok&=(i>=k);
for(ll &i:b)cin>>i;
if(!ok){
cout<<"Impossible"<<nl;
return 0;
}
ll sm2=0;
dp[0]=0;
for(ll i=1;i<=m;i++){
for(ll j=sm2;j>=0;j--){
if(dp[j]!=-1)dp[j+b[i-1]]=max(dp[j+b[i-1]],dp[j]+min(n,b[i-1]));
}
sm2+=b[i-1];
}
for(ll i=sm;i<=sm*sm*sm;i++){
if(dp[i]>=n*k){
cout<<i-sm<<nl;
return 0;
}
}
cout<<"Impossible"<<nl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |