제출 #976838

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
9768382024-05-07 07:30:49tamir1수열 (APIO14_sequence)C++17
62 / 100
637 ms82200 KiB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[2][100001],sum[100001],ans;
int n,k,i,l,a[100001],dp2[201][100001],idx;
vector<int> v;
struct line{
ll k,d;
int idx;
};
ll val(line a,ll x){
return a.k*x+a.d;
}
double intt(line a,line b){
return double(b.d-a.d)/(a.k-b.k);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k;
for(i=1;i<=n;i++){
cin >> a[i];
sum[i]=sum[i-1]+a[i];
}
for(l=1;l<=k;l++){
deque<line> q;
q.push_back({sum[l-1],dp[0][l-1]-sum[n]*sum[l-1],l-1});
for(i=l;i<n;i++){
while(q.size()>=2 && val(q.back(),sum[i])<=val(q[q.size()-2],sum[i])) q.pop_back();
dp[1][i]=sum[n]*sum[i]-sum[i]*sum[i]+val(q.back(),sum[i]);
dp2[l][i]=q.back().idx;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...