This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void nosol(){
cout << "Impossible\n";
exit(0);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cerr.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n + 1);
vector<int> b(m + 1);
ll sa = 0, sb = 0;
for(int i = 1; i <= n; i++) cin >> a[i], sa += a[i];
for(int i = 1; i <= m; i++) cin >> b[i], sb += b[i];
sort(b.begin() + 1, b.end());
if(k > m || sa > sb){
nosol();
}
for(int i = 1; i <= n; i++) if(a[i] < k) nosol();
assert(m <= 2);
if(k == 1){
if(sa <= b[1]) cout << b[1] - sa << "\n";
else if(sa <= b[2]) cout << b[2] - sa << "\n";
else cout << b[1] + b[2] - sa << "\n";
return 0;
}
if(n > b[1]) nosol();
cout << b[1] + b[2] - sa << "\n";
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... |