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;
int main() {
ll n, m;
cin >> n >> m;
ll a[n], b[n];
for(int i=0; i<n; i++) cin >> a[i];
for(int i=0; i<n; i++) cin >> b[i];
int c[n];
memset(c, 0, sizeof c);
if(m==1) {
ll ans = (ll)1<<60;
for(int i=0; i<n; i++) {
ans = min(ans, max(a[i], b[i]));
}
cout << ans;
}
else {
set<pair<ll, ll> > s;
for(int i=0; i<n; i++) {
s.insert(make_pair(0, i));
}
for(int i=0; i<m*n; i++) {
pair<ll, ll> p = *s.begin();
s.erase(s.find(p));
if(c[p.second]<m && a[p.second]>b[p.second]) {
p.first += a[p.second];
c[p.second]++;
}
else p.first += b[p.second];
s.insert(p);
}
//for(auto p : s) cout << p.first << ' ';
cout << s.begin()->first;
}
}
# | 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... |