Submission #501231

#TimeUsernameProblemLanguageResultExecution timeMemory
501231nightySjeckanje (COCI21_sjeckanje)C++14
15 / 110
2055 ms440 KiB
#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 (stderr)

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) {
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...