답안 #386326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386326 2021-04-06T11:40:51 Z phathnv Sjeckanje (COCI21_sjeckanje) C++11
55 / 110
48 ms 748 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 3007;

int n, q, a[N];
ll b[N], dp[N][2];

int getSign(ll x){
    if (x < 0)
        return -1;
    else if (x == 0)
        return 0;
    else
        return 1;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> q;
    if (max(n, q) > 3000)
        return 0;

    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i < n; i++)
        b[i] = a[i + 1] - a[i];

    while (q--){
        int l, r, x;
        cin >> l >> r >> x;
        if (l > 1)
            b[l - 1] += x;
        if (r < n)
            b[r] -= x;
//        cerr << "b: ";
//        for(int i = 1; i < n; i++)
//            cerr << b[i] << ' ';
//        cerr << endl;
        dp[0][0] = dp[0][1] = 0;
        for(int i = 1; i < n; i++){
            dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
            dp[i][1] = dp[i - 1][0] + abs(b[i]);
            if (getSign(b[i - 1]) * getSign(b[i]) != -1)
                dp[i][1] = max(dp[i][1], dp[i - 1][1] + abs(b[i]));
        }
        cout << max(dp[n - 1][0], dp[n - 1][1]) << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 48 ms 620 KB Output is correct
8 Correct 42 ms 620 KB Output is correct
9 Correct 42 ms 748 KB Output is correct
10 Correct 45 ms 620 KB Output is correct
11 Correct 43 ms 620 KB Output is correct
12 Correct 37 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 48 ms 620 KB Output is correct
8 Correct 42 ms 620 KB Output is correct
9 Correct 42 ms 748 KB Output is correct
10 Correct 45 ms 620 KB Output is correct
11 Correct 43 ms 620 KB Output is correct
12 Correct 37 ms 620 KB Output is correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Halted 0 ms 0 KB -