제출 #173466

#제출 시각아이디문제언어결과실행 시간메모리
173466emil_physmathBigger segments (IZhO19_segments)C++17
0 / 100
2 ms380 KiB
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef double ldouble; typedef long long llong; typedef unsigned int uint; template<typename T1, typename T2> ostream& operator<<(ostream& str, const pair<T1, T2>& p) { return str << "{" << p.first << ", " << p.second << "}"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int& x: a) cin >> x; vector<llong> pref(n); for (int i = 0; i < n; ++i) pref[i] = a[i] + (i ? pref[i - 1] : 0); vector<pair<int, llong>> dp(n); for (int i = 0; i < n; ++i) dp[i] = {1, pref[i]}; for (int i = 0; i < n; ++i) { int j = -1; int l = i + 1, r = n - 1; while (l <= r) { int m = (l + r) / 2; if (pref[m] - pref[i] >= dp[i].second) { j = m; r = m - 1; } else l = m + 1; } if (j != -1) { dp[j] = max(pair<int, llong>{dp[j].first, -dp[j].second}, {dp[i].first + 1, -(pref[j] - pref[i])}); dp[j].second *= -1; // cerr << "i: " << i << "; " << "j: " << j << "\t" << dp[j] << endl; } } /*for (int i = 0; i < dp.size(); ++i) cerr << "dp[" << i << "] = " << dp[i] << endl;*/ cout << max_element(dp.begin(), dp.end())->first << endl; }
#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...