General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
81825489 Practice:
ggdwbg
1359D - 47 C++17 (GCC 9-64) Accepted 46 ms 2028 KB 2020-05-28 22:38:54 2020-05-29 08:06:47
→ Source
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#ifdef LOCAL
template <class T> ostream &operator<<(ostream &str, const vector<T> &vec) {
  str << '[';
  for (auto it = vec.begin(); it != vec.end(); it++) {
    if (it != vec.begin())
      str << ", ";
    str << *it;
  }
  str << ']';
  return str;
}
#define var(x) "[" << #x << ": " << x << "] "
#define dbg cerr << "  line " << __LINE__ << ": "
#else
#define var(x) 0
struct dbg_cls {
  template <class T> dbg_cls &operator<<(const T &oth) { return *this; }
} dbg;
#endif
using ll = long long;
int main(int argc, char **argv) {
  ios::sync_with_stdio(false), cin.tie(0);

  auto kadanes = [&](vector<ll>& v) {
    ll ans = -1e18, s = 0;
    for (auto p : v) {
      s += p;
      ans = max(ans, s);
      s = max(s, 0ll);
    }
    return ans;
  };

  int n;
  cin >> n;
  vector<ll> v(n);
  unordered_map<int, vector<int>> ind;

  for (int i = 0; i < n; i++) {
    cin >> v[i];
    ind[v[i]].pb(i);
  }

  ll ans = 0;
  for (int i = 30; i >= -30; i--) {
    if (ind[i].empty())
      continue;
    ans = max(ans, kadanes(v) - i);
    for (auto j : ind[i])
      v[j] = -1e9;
  }
  cout << ans << '\n';

  return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details