2021-07-17 AcWing 第八场周赛 3771. 选取石子
输入样例1:
6 10 7 1 9 10 15
输出样例1:
26
输入样例2:
1 400000
输出样例2:
400000
输入样例3:
7 8 9 26 11 12 29 14
输出样例3:
55
简单变动一下便是哈希,一开始用dp推了好半天也没做出来
#include <iostream>
#include <vector>
#include <map>
using ll = long long;
using namespace std;
int main()
{
int n,x;
ll res=-1;
cin>>n;
map<int, ll> b;
for (int i = 1; i <= n; i ++ ){
scanf("%d", &x);
b[x-i] += x;
}
for (auto& [i,j]: b){
res=max(res,b[i]);
}
cout << res;
return 0;
}
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/15799166.html