이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
void open(){
if(fopen("input.inp", "r")){
freopen("input.inp", "r", stdin);
//freopen("output.out", "w", stdout);
}
}
const int maxn = 3e5 + 5;
int n, m;
int A[maxn], B[maxn];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
open();
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> A[i];
}
for(int i = 1; i <= n; i++){
cin >> B[i];
}
if(m == 1){
int result = 1e9 + 7;
for(int i = 1; i <= n; i++){
result = min(result, max(A[i], B[i]));
}
cout << result << endl;
return 0;
}
if(m * n <= maxn){
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for(int i = 1; i <= n; i++){
pq.push({0, i});
}
while(m--){
int temp = n;
vector<bool> check(n + 1, false);
while(temp--){
pair<int, int> first = pq.top();
pq.pop();
int old_val = first.first;
int pos = first.second;
if(A[pos] > B[pos] && !check[pos]){
check[pos] = true;
old_val += A[pos];
}else{
old_val += B[pos];
}
pq.push({old_val, pos});
}
}
cout << pq.top().first << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void open()':
Main.cpp:8:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | freopen("input.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |