제출 #499326

#제출 시각아이디문제언어결과실행 시간메모리
499326AktanK개의 묶음 (IZhO14_blocks)C++17
53 / 100
1087 ms1880 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ft first
#define sc second
using namespace std;
const int mod=1e9+7,INF=1e17;

int n,k,dp[105][1000005],mx=-INF,a[1000005];
main(){
   cin >> n >> k;
   int res=0;
   for(int i=1;i<=n;i++){
   	cin >> a[i];
   	res+=a[i];
   	if(i<=k){
   		dp[i][i]=res;
	   }
   }
   for(int i=1;i<=n;i++){
   	mx=max(mx,a[i]);
   	dp[1][i]=mx;
   }
   for(int i=2;i<=k;i++){
   	for(int j=i+1;j<=n;j++){
   		int ans=INF,h=a[j];
   		for(int l=j-1;l>=i-1;l--){
   			if(dp[i-1][l]+h<ans){
   				ans=dp[i-1][l]+h;
			   }
			   h=max(h,a[l]);
		   }
		   dp[i][j]=ans;
	   }
   }
   cout << dp[k][n];
}

컴파일 시 표준 에러 (stderr) 메시지

blocks.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...