제출 #84776

#제출 시각아이디문제언어결과실행 시간메모리
84776Mahdi_Jfri수열 (APIO14_sequence)C++14
0 / 100
77 ms2360 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int maxn = 1e5 + 20; const int maxk = 2e2 + 20; int l[maxn] , r[maxn] , sum[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n , k; cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> sum[i] , sum[i] += sum[i - 1]; l[i] = 1 , r[i] = n; } ll res = 0; for(int i = 0; i < k; i++) { ll mx = 0; for(int j = 1; j <= n; j++) if(r[j] > j) mx = max(mx , 1LL * (sum[r[j]] - sum[j]) * (sum[j] - sum[l[j] - 1])); for(int j = 1; j <= n; j++) if(r[j] > j && 1LL * (sum[r[j]] - sum[j]) * (sum[j] - sum[l[j] - 1]) == mx) { for(int x = j + 1; x <= r[j]; x++) l[x] = j + 1; for(int x = l[j]; x <= j; x++) r[x] = j; break; } res += mx; } cout << res << endl; for(int i = 1; r[i] < n; i = r[i] + 1) cout << r[i] << " "; cout << 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...
#Verdict Execution timeMemoryGrader output
Fetching results...