Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <map>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<long long> v(n);
- for(long long &x : v) {
- cin >> x;
- }
- vector<long long> dp(n, 0);
- dp[0] = v[0];
- long long ret = v[0];
- for(int i = 1; i < n; ++i) {
- dp[i] = max(dp[i - 1] + v[i], v[i]);
- ret = max(ret, dp[i]);
- }
- cout << ret << endl;
- return 0;
- }
- /*
- 10
- 404 882
- 690 974
- 201 255
- 800 933
- 525 819
- 457 601
- 461 978
- 832 932
- 699 804
- 795 860
- */
Advertisement
Add Comment
Please, Sign In to add comment