https://www.acmicpc.net/problem/11001
11001번: 김치
첫 번째 줄에 날짜의 수와 시간 제한 N, D가 주어진다. (1 ≤ D ≤ N ≤ 100,000) 두 번째 줄에 온도 Ti가 주어진다. N-1 이하의 정수 i에 대해서 Ti >= Ti+1을 만족하며, 109 이하의 자연수이다. 세 번째 줄에
www.acmicpc.net
Tag : dnc opt
문제요약
(숙성시간)*(꺼낼 때의 온도)+(넣은 날의 가치)의 최대를 구하는 문제다.
dnc opt(분할정복 최적화)를 사용하면 이를
P의 정의가 위와 같을 때
proof)
P의 정의에 의해 다음 식이 성립한다.
이를 정리하면 아래와 같다.
따라서
(그냥 monge array인거 보이는게 낫다)
+ 맞은사람 1등먹었다 뿌듯

전체코드
#include "bits/stdc++.h"
#define pb push_back
#define fi first
#define se second
#define all(x) ((x).begin()), ((x).end())
#define compress(x) sort(all(x)), (x).erase(unique(all(x)),(x).end())
#define siz(x) ((int)((x).size()))
#define endl '\n'
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
template<typename T>T rmin(T &a,T b){return a=min<T>(a,b);}
template<typename T>T rmax(T &a,T b){return a=max<T>(a,b);}
ll N,D;
ll T[101010];
ll v[101010];
ll P[101010];
ll dp[101010];
void dnc(ll s,ll e,ll l,ll r){
if(s>e)return;
ll m=(s+e)/2;
for(ll i=max(l,m);i<=min(r,m+D);i++){
if((i-m)*T[i]+v[m]>dp[m]){
dp[m]=(i-m)*T[i]+v[m];
P[m]=i;
}
}
dnc(s,m-1,l,P[m]);
dnc(m+1,e,P[m],r);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>N>>D;
for(int i=1;i<=N;i++)cin>>T[i];
for(int i=1;i<=N;i++)cin>>v[i];
dnc(1,N,1,N);
cout<<*max_element(dp+1,dp+N+1)<<endl;
}
'BOJ' 카테고리의 다른 글
[BOJ 18313] Cave Paintings (0) | 2021.12.29 |
---|---|
[BOJ 13261] 탈옥 (1) | 2021.12.23 |
[BOJ 15462] The Bovine Shuffle (0) | 2021.11.25 |
[BOJ 15770] QueryreuQ (0) | 2021.11.25 |
[BOJ 11973] Angry Cows (Silver) (0) | 2021.11.25 |