观光景点组合得分问题 | 豆包MarsCode AI刷题

43 阅读1分钟
#include <bits/stdc++.h>

using namespace std;

int solution(vector<int> values) {
    if(values.size() == 1) return 0;
    int maxv = 0 , res = 0;

    for(int i = 0 ; i < values.size() ; i ++)
    {
        res = max(res , values[i] - i + maxv);
        maxv = max(maxv , values[i] + i);
    }
    return res; // Placeholder return
}

int main() {
    cout << (solution({8, 3, 5, 5, 6}) == 11) << endl;
    cout << (solution({10, 4, 8, 7}) == 16) << endl;
    cout << (solution({1, 2, 3, 4, 5}) == 8) << endl;
    return 0;
}