求助,0分

P1725 琪露诺

程义轩 @ 2020-10-24 09:00:26

这个哪里错了?

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int ans = 0;
    int N, L, R;
    cin >> N >> L >> R;
    int* ice = new int[N];
    for (int i = 0; i < N; i++) {
        cin >> ice[i];
    }
    int cnt = 0;
    int i = 0, j = 0;
    while ((i < N || j < N) && cnt + L <= N && cnt + R <= N) {
        if (ice[cnt + L] > ice[cnt + R]) {
            i++;
            ans += ice[cnt + L];
            cnt += L;
        }
        else if (ice[cnt + L] < ice[cnt + R]) {
            j++;
            ans += ice[cnt + R];
            cnt += R;
        }
    }
    cout << ans << endl;
    return 0;
}

by AuCloud @ 2020-10-24 09:05:17

这个难道不是[i+L,i+R]内一格吗///

@jerryjames您写的是只能跳到i+L或i+R吧//


by AuCloud @ 2020-10-24 09:05:38

@jerryjames


|