이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
ll dp[250005][205];
bool visited[250005][205];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
FOR(i,0,250005)FOR(j,0,205) dp[i][j] = -100000000000000000, visited[i][j] = 0;
ll n,k;
cin >> n >> k;
vector<ll> price(n), sell(n);
FOR(i,0,n) cin >> price[i];
FOR(i,0,n) cin >> sell[i];
FOR(i,0,n) dp[i][0] = 0;
FOR(i,0,n){
FOR(j,0,204){
dp[i+1][j+1] = max(dp[i][j] + sell[i] - price[i], dp[i][j+1] - price[i]);
}
}
ll ans = -100000000000000000;
FOR(i,k,n+1){
ans = max(ans, dp[i][k]);
}
FOR(i,k,n+1){
if (dp[i][k]==ans) visited[i][k] = 1;
}
vector<ll> used(n);
FORNEG(i,n-1,-1){
FORNEG(j,203,-1){
if (dp[i+1][j+1] == dp[i][j] + sell[i] - price[i]&& visited[i+1][j+1]){
visited[i][j] = 1;
used[i]=1;
}
if (dp[i+1][j+1] == dp[i][j+1] - price[i]){
visited[i][j+1] = 1;
}
}
}
cout << ans << endl;
FOR(i,0,n) cout << used[i];
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |