0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 15:18:46 +00:00

P8365 [LNOI2022] 吃

https://www.luogu.com.cn/record/85390253
This commit is contained in:
Baoshuo Ren 2022-08-28 21:32:08 +08:00
parent 6ba378d498
commit 6db75723ce
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

61
Luogu/P8365/P8365.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
int n, a[N], b[N], ans = 1;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
for (int i = 1; i <= n; i++) {
if (a[i] == 1) {
ans = (static_cast<long long>(ans) + b[i]) % mod;
a[i] = -1;
}
}
long double max = ans;
int max_id = -1;
for (int i = 1; i <= n; i++) {
if (~a[i]) {
long double t = static_cast<long double>(static_cast<long long>(ans) + b[i]) / a[i];
if (t > max) {
max = t;
max_id = i;
}
}
}
if (~max_id) {
a[max_id] = -1;
ans = (static_cast<long long>(ans) + b[max_id]) % mod;
}
for (int i = 1; i <= n; i++) {
if (~a[i]) {
ans = static_cast<long long>(ans) * a[i] % mod;
}
}
cout << ans << endl;
return 0;
}