This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define int long long
#define ld long double
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int N = 200;
const int X = N * N;
const int K = 500;
const int MOD = 1e9 + 7;
const int LOG = 21;
const int INF = 1e17;
int dp[N][X];
signed main(){ios::sync_with_stdio(false);cin.tie(0);
int n;
cin>>n;
int A[n], B[n];
for(int i = 0;i <n;i++)cin>>A[i];
for(int i = 0;i < n;i++)cin>>B[i];
if(n > 100){ // Sub 2 :D
cout<<max(0ll, A[0] * (n - 2));
return 0;
}
int sum = 0;
for(int i = 0;i <n;i++)sum += A[i] - B[i];
for(int i = n - 1;i >= 0;i--){
if(A[i] <= sum)sum -= A[i], A[i] = 0;
else{
A[i] -= sum;
break;
}
}
for(int i = 0;i <= n;i++){
for(int j = 0;j < X;j++)dp[i][j] = -INF;
}
dp[0][0] = 0;
for(int i = 0;i < n;i++){
for(int j = 0;j < X;j++){
for(int k = 0;k <= min(A[i] + j, B[i]);k++){
dp[i + 1][A[i] + j - k] = max(dp[i + 1][A[i] + j - k], dp[i][j] + min(j, k));
}
}
}
int ans = -INF;
for(int i = 0;i < X;i++)ans = max(ans, dp[n][i] - i);
cout<<ans;
}
# | 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... |