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 <iostream>
#include <queue>
using namespace std;
const int nmax = 300005;
unsigned long long n, m, a[nmax], b[nmax], v[nmax];
priority_queue< pair<unsigned long long, unsigned long long> > H, H2;
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++)
cin >> a[i];
for(int i = 1; i <= n; i ++)
{
cin >> b[i];
v[i] = max(a[i], b[i]);
}
for(int i = 1; i <= n; i ++)
{
H.push({v[i] * m, i});
H2.push({-v[i] * m , i});
}
int ok = 1;
while(ok)
{
unsigned long long maxi = H.top().first;
unsigned long long pozmax = H.top().second;
unsigned long long mini = -H2.top().first;
unsigned long long pozmin = H2.top().second;
if(maxi - v[pozmax] <= mini)
{
ok = 0;
continue;
}
maxi -= v[pozmax];
if(v[pozmin] == a[pozmin])
mini += b[pozmin];
else
mini += a[pozmin];
H.pop(); H2.pop();
H.push({maxi, pozmax});
H2.push({-mini, pozmin});
}
cout << -H2.top().first;
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
14 | for(int i = 1; i <= n; i ++)
| ~~^~~~
Main.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
17 | for(int i = 1; i <= n; i ++)
| ~~^~~~
Main.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
23 | for(int i = 1; i <= n; i ++)
| ~~^~~~
# | 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... |