답안 #501231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501231 2022-01-02T16:25:19 Z nighty Sjeckanje (COCI21_sjeckanje) C++14
15 / 110
2000 ms 440 KB
#include <bits/stdc++.h>

using namespace std;

long long calc(vector<long long>& a) {
    vector<long long> dp(a.size(), 0); // max val if ends in i
    dp[0] = 0;
    for (int i = 1; i < a.size(); ++i) {
        long long maxVal = a[i], minVal = a[i];
        for (int j = i - 1; j >= 0; --j) {
            dp[i] = max(dp[i], dp[j] + maxVal - minVal);
            maxVal = max(maxVal, a[j]);
            minVal = min(minVal, a[j]);
        }
        dp[i] = max(dp[i], maxVal - minVal);
    }
    return dp.back();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<long long> a(n);
    for (auto& i : a) {
        cin >> i;
    }
    while (q--) {
        int l, r, x;
        cin >> l >> r >> x;
        --l, --r;
        for (int i = l; i <= r; ++i) {
            a[i] += x;
        }
        cout << calc(a) << '\n';
    }
    return 0;
}

Compilation message

Main.cpp: In function 'long long int calc(std::vector<long long int>&)':
Main.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 1; i < a.size(); ++i) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 312 KB Output is correct
2 Correct 7 ms 316 KB Output is correct
3 Correct 7 ms 204 KB Output is correct
4 Correct 7 ms 316 KB Output is correct
5 Correct 7 ms 316 KB Output is correct
6 Correct 8 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 312 KB Output is correct
2 Correct 7 ms 316 KB Output is correct
3 Correct 7 ms 204 KB Output is correct
4 Correct 7 ms 316 KB Output is correct
5 Correct 7 ms 316 KB Output is correct
6 Correct 8 ms 316 KB Output is correct
7 Execution timed out 2055 ms 440 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 312 KB Output is correct
2 Correct 7 ms 316 KB Output is correct
3 Correct 7 ms 204 KB Output is correct
4 Correct 7 ms 316 KB Output is correct
5 Correct 7 ms 316 KB Output is correct
6 Correct 8 ms 316 KB Output is correct
7 Execution timed out 2055 ms 440 KB Time limit exceeded
8 Halted 0 ms 0 KB -