竞赛讨论区 > A题,全WA了。有大佬能帮忙看看错哪了吗?
头像
Askr_Yggdrasills
发布于 2022-01-24 08:12
+ 关注

A题,全WA了。有大佬能帮忙看看错哪了吗?

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int a[100010];
    int t, n, l, r, max, tmp;
    vector<int> ans;

    //输入询问次数
    cin >> t;
    for (int i = 0; i < t; i++) {
        //输入数据数
        cin >> n;

        //输入数据
        for (int j = 1; j <= n; j++) {
            cin >> a[j];
        }

        //初始化条件
        ans.clear();
        l = 1;
        max = 0;

        //遍历数据
        for (r = 1; r <= n; r++) {
            if (r == n || a[r + 1] < a[r]) {
                tmp = a[r] - a[l];

                if (tmp < max) {
                    continue;
                }
                if (tmp > max) {
                    ans.clear();
                    max = tmp;
                }
                ans.push_back(l);
                ans.push_back(r);
                l = r + 1;
            }
        }

        //打印结果
        for (int j = 0; j < ans.size(); j++) {
            cout << ans[j] << " ";
        }
        cout << endl;
    }
    return 0;
}

全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐