이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define maxn 100010
#define maxk 110
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
typedef long long ll;
using namespace std;
const char *fi="BLOCKS.INP";
const char *fo="BLOCKS.OUT";
int n,k,A[maxn],P[maxn];
ll F[maxn][maxk];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen(fi,"r",stdin);
// freopen(fo,"w",stdout);
cin>>n>>k;
FOR(i,1,n) cin>>A[i];
P[0]=0;
FOR(i,1,n) P[i]=max(P[i-1],A[i]);
FOR(i,1,n) F[i][1]=P[i];
FOR(j,2,k){
int maxright=0; ll sumleft=F[j-1][j-1];
FOR(i,j,n){
maxright = max(maxright,A[i]);
// cout<<i<<' '<<j<<' '<<sumleft<<' '<<maxright<<' '<<(F[i-1][j-1]+P[i-1]+A[i])<<endl;
if (sumleft+maxright < F[i-1][j-1]+A[i]) F[i][j]=sumleft+maxright;
else {
sumleft = F[i-1][j-1];
maxright = A[i];
F[i][j]=F[i-1][j-1]+A[i];
}
}
}
cout<<F[n][k];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp: In function 'int main()':
blocks.cpp:18:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(fi,"r",stdin);
~~~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |