#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e4;
const ll inf = 1e17;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 500;
int n, m, k;
int a[mxn];
int b[mxn];
bool done[mxn*mxn];
map<pair<pii, pii>, bool> mapa;
void solve(int h, int pos, int sum, int p){
if(mapa[{{h, pos}, {sum,p}}]) return;
mapa[{{h, pos}, {sum,p}}] = true;
if(h == k-1 && pos == n){
done[sum] = true;
}
if(p == m) return;
int bound = n;
if(h == k-1) bound = n-pos;
int extr = 0;
int add = b[p];
if(b[p] > bound){
extr = b[p]-bound;
add = bound;
}
if(pos + add > n){
solve(h+1, pos+add-n, sum+extr, p+1);
}
else{
solve(h, pos+add, sum + extr, p+1);
}
solve(h, pos, sum, p+1);
}
void solve(){
cin >> n >> m >> k;
int rem = 0;
fr(i, 0, n){
cin >> a[i];
rem += a[i]-k;
}
fr(i, 0, m){
cin >> b[i];
}
fr(i, 0, n){
if(a[i] < k){
cout<<"Impossible"<<endl;
return;
}
}
solve(0, 0, 0, 0);
int ans = -1;
fr(i, rem, mxn*mxn) if(done[i]){ ans = i; break;}
if(ans == -1) cout<<"Impossible"<<endl;
else cout<<ans-rem<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
8 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1083 ms |
132200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
5496 KB |
Output is correct |
2 |
Correct |
519 ms |
41200 KB |
Output is correct |
3 |
Correct |
10 ms |
1664 KB |
Output is correct |
4 |
Correct |
9 ms |
1536 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
8 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
14 |
Execution timed out |
1083 ms |
132200 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |