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;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ll n,m;cin>>n>>m;
vi a(n);rep(i,0,n)cin>>a[i];
vi b(n);rep(i,0,n)cin>>b[i];
bool eq = true;
rep(i,0,n)if(a[i]!=b[i]) eq=false;
ll worst = 1e18;
if(m==1){
rep(i,0,n) worst=min(worst,m*max(a[i],b[i]));
}else if(n*m <= 300000){
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
rep(i,0,n) pq.push({0,i});
rep(_,0,n*m){
auto p = pq.top(); pq.pop();
pq.push({p.F + a[p.S], p.S});
}
worst = pq.top().F;
}
cout<<worst<<endl;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:20:7: warning: variable 'eq' set but not used [-Wunused-but-set-variable]
20 | bool eq = true;
| ^~| # | 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... |