Submission #169367

#TimeUsernameProblemLanguageResultExecution timeMemory
169367SamAndBigger segments (IZhO19_segments)C++17
100 / 100
147 ms18912 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 500005; int n; int a[N]; long long p[N]; pair<int, long long> dp[N]; pair<int, long long> mer(const pair<int, long long>& l, const pair<int, long long>& r) { if (l.first > r.first) return l; if (l.first < r.first) return r; if (l.second < r.second) return l; return r; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) p[i] = p[i - 1] + a[i]; for (int i = 0; i < n; ++i) { dp[i + 1] = mer(dp[i + 1], m_p(dp[i].first, dp[i].second + a[i + 1])); int l = i + 1, r = n; int ans = -1; while (l <= r) { int m = (l + r) / 2; if (p[m] - p[i] >= dp[i].second) { ans = m; r = m - 1; } else l = m + 1; } if (ans != -1) dp[ans] = mer(dp[ans], m_p(dp[i].first + 1, p[ans] - p[i])); } printf("%d\n", dp[n].first); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
segments.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...