AtCoder D

http://arc063.contest.atcoder.jp/tasks/arc063_b

因为每次都是选取最大值,那么用dp[i]表示第i个数结尾能得到最大是多少。

其实就是用a[i]去减去左边最小的那个数字。

然后就是统计有多少个一样的最大值了。。

hack点

T是没用的,我被坑了,以为最多只能T / 2次,那么答案是min(T / 2, cnt_max)

但是不是。就算你T / 2只是1,那么,我也可以走不同的道路来取得max,所以要改变的cnt_max还是要改变。

和T无关。。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e6 + 20;
int dp[maxn];
void work() {
    int n, t;
    scanf("%d%d", &n, &t);
    if (n == 1) while(1);
    int mi = (1LL << 31) - 1;
    int mx = -((1LL << 31) - 1);
    for (int i = 1; i <= n; ++i) {
        int x;
        scanf("%d", &x);
        dp[i] = max(0, x - mi);
        mi = min(mi, x);
        mx = max(mx, dp[i]);
    }
    int tim = 0;
    for (int i = 1; i <= n; ++i) {
        tim += dp[i] == mx;
    }
    int ans = tim;
    cout << ans << endl;
}

int main() {
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    work();
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6036796.html