제출 #332434

#제출 시각아이디문제언어결과실행 시간메모리
332434vitkishloh228수열 (APIO14_sequence)C++14
0 / 100
18 ms1900 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; #define int long long int32_t main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> pr(n + 1); for (int i = 0; i < n; ++i) pr[i + 1] = pr[i] + a[i]; int needsum = pr[n] / (k + 1); int it = 0; int cursum = 0; int ans = 0; vector<int> ans1; for (int i = 0; i < k; ++i) { int pos1 = upper_bound(pr.begin(), pr.end(), needsum + cursum) - pr.begin() - 1; //cout << pr[pos1] << endl; ans += ((pr[pos1] - pr[it]) * (pr[n] - pr[pos1])); ans1.push_back(pos1); it = pos1 ; cursum = pr[pos1]; } cout << ans << '\n'; for (auto elme : ans1) cout << elme << ' '; }
#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...