#include <bits/stdc++.h>
// #define MULTI_TEST_CASE
// #define TEST_TEXT
using namespace std;
#define ll long long
#define MAX(a, b) (a) = max((a), (b))
#define MIN(a, b) (a) = min((a), (b))
#define all(a) (a).begin(), (a).end()
#define sortedpair(a, b) {min((a), (b)), max((a), (b))}
const ll MOD = 1e9+7;
void solve(){
int n, m, k; cin>>n>>m>>k;
vector<int> a(n);
for(int&i:a)cin>>i;
vector<int> b(m);
for(int&i:b)cin>>i;
if(m == 1){
if(k > 1){
cout<<"Impossible"<<endl;
return;
}
int s = 0;
for(int i:a)s += i;
if(s>b[0]){
cout<<"Impossible"<<endl;
return;
} else {
cout<<b[0]-s<<endl;
return;
}
} else {
if(k > 2){
cout<<"Impossible"<<endl;
return;
}
int s = 0;
for(int i:a)s += i;
if(s>b[0]+b[1]){
cout<<"Impossible"<<endl;
return;
}
if(k == 1){
if(b[0] >= s && b[1] >= s){
cout<<min(b[0], b[1])-s<<endl;
} else if(b[0] >= s){
cout<<b[0]-s<<endl;
} else if(b[1] >= s){
cout<<b[1]-s<<endl;
} else {
cout<<b[0]+b[1]-s<<endl;
}
} else {
if(b[0]<n || b[1]<n){
cout<<"Impossible"<<endl;
return;
} else {
cout<<b[0]+b[1]-s<<endl;
return;
}
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int _t = 1;
#ifdef MULTI_TEST_CASE
cin >> _t;
#endif
for(int _i = 0; _i < _t; _i++){
#ifdef TEST_TEXT
cout<<"Case #"<<_i+1<<": ";
#endif
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |