洛谷 - P7286
题意
潇有一个数组
潇定义
潇想知道对于任意的
思路
显然第二种
令
所以我们枚举
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e6 + 3;
int n;
struct shu{
ll s;
int id;
} k[N];
int max_id;
ll ans;
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> k[i].s;
k[i].id = i;
}
sort(k + 1, k + 1 + n, [](const shu & x, const shu & y){ return x.s > y.s; });
for(int i = 1; i <= n; i ++){
ans = max(ans, k[i].s * (k[i].id + max_id));
max_id = max(max_id, k[i].id);
}
cout << ans;
return 0;
}