제출 #684536

#제출 시각아이디문제언어결과실행 시간메모리
684536phoenix수열 (APIO14_sequence)C++17
0 / 100
27 ms2388 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6; ll value[N], pref[N]; int n, k; vector<pair<int, int>> st; ll res = 0; vector<int> res_v; int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> value[i]; pref[i] = pref[i - 1] + value[i]; } st.push_back({1, n}); for(int iter = 1; iter <= k; iter++) { ll mx = -1, p_i = 0, inx = 0; for(int p = 0; p < (int)st.size(); p++) { int l = st[p].first, r = st[p].second; for(int i = l; i < r; i++) { if((pref[i] - pref[l - 1]) * (pref[r] - pref[i]) > mx) { mx = (pref[i] - pref[l - 1]) * (pref[r] - pref[i]); p_i = p; inx = i; } } } res += mx; res_v.push_back(inx); st.push_back({inx + 1, st[p_i].second}); st[p_i].second = inx; } cout << res << '\n'; for(int c : res_v) cout << c << ' '; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...