이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
vector<int> v[90001];
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
int a[n], b[m];
int x = 0;
bool bad = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
x += a[i];
if(a[i] < k)
bad = 1;
}
int sum = 0;
for(int i = 0; i < m; i++) {
cin >> b[i];
sum += b[i];
}
if(bad) {
cout << "Impossible";
return 0;
}
sort(b, b + n);
for(int i = m - 1; i >= 0; i--) {
for(int j = sum; j >= b[i]; j--) {
if(j == b[i] || v[j - b[i]].size()) {
if(v[j - b[i]].size() + 1 > v[j].size()) {
v[j] = v[j - b[i]];
v[j].push_back(b[i]);
}
}
}
}
for(int i = x; i <= sum; i++) {
if(v[i].size() >= k) {
int y = 0, z = 0;
for(int o : v[i]) {
y += o;
z += min(n, o);
}
if(y >= x && z >= n * k) {
cout << y - x;
return 0;
}
}
}
cout << "Impossible";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
kitchen.cpp: In function 'int main()':
kitchen.cpp:55:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | if(v[i].size() >= k) {
| ~~~~~~~~~~~~^~~~
# | 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... |