QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#600455 | #5005. Geekflix | Sound_Medium | WA | 4ms | 4376kb | C++23 | 2.0kb | 2024-09-29 16:41:35 | 2024-09-29 16:41:35 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve () {
int n, m;
cin >> n >> m;
vector <int> a (n + 1);
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
vector <int> b (n + 1);
for (int i = 1; i <= n; i ++) {
cin >> b[i];
}
vector <vector<int>> dp1 (n+1,vector<int>(m + 1));
vector <vector<int>> dp2 (n+1,vector<int>(m + 1));
auto work = [&] ()->vector<vector<int>> {
vector <vector<int>> dp (n+1,vector<int>(m + 1,0));
dp[1][1] = a[1];
int maxx = 0;
for (int i = 1; i <= n; i ++) {
// auto ndp = dp;
for (int j = 2; j <= m; j ++) {
dp[i][j] = dp[i-1][j - 1];
}
for (int j = 1; j <= m; j ++) {
for (int k = 1; a[i] - (k - 1) * b[i] > 0 && k + 1 <= j; k ++) {
dp[i][j] = max (dp[i][j], dp[i-1][j - k - 1] + k * a[i] - k * (k - 1) / 2 * b[i]);
}
}
// dp = move (ndp);
// maxx = max (maxx, *max_element (dp.begin (), dp.end ()));
}
return dp;
};
dp1= work ();
reverse (a.begin () + 1, a.end ());
reverse (b.begin () + 1, b.end ());
dp2=work();
// cout<<dp2[1][1]<<endl;;
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
dp2[i][j]=max(dp2[i][j],dp2[i][j-1]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int maxx=0;
for(int k=1;k<=n-i;k++){
if(m-i-j>0)
maxx=max(maxx,dp2[k][m-i-j]);
}
ans=max(ans,dp1[i][j]+maxx);
// if(i==2)
// cerr<<dp1[i][j]<<" "<<(m-i-j>0)*dp2[n-i][m-i-j]<<endl;
}
}
cout << ans << '\n';
}
signed main () {
ios::sync_with_stdio (false);
cin.tie (nullptr);
int T = 1;
// cin >> T;
while (T --) {
solve ();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
3 10 10 10 10 5 3 1
output:
67
result:
ok single line: '67'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
5 10 1 2 3 4 5 0 1 2 3 4
output:
16
result:
ok single line: '16'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 5 1 5000 1 1 5000 1 3000 1 1 3000
output:
10000
result:
ok single line: '10000'
Test #4:
score: -100
Wrong Answer
time: 4ms
memory: 4376kb
input:
100 500 1676 3766 611 4073 4277 633 1921 650 4074 4382 1027 1849 861 1199 1411 21 2021 2227 1829 2487 1415 4006 3680 2374 2332 1461 4384 3874 3053 2968 1347 4728 3085 3309 3800 2362 3941 2072 3011 4366 1454 4038 1214 3666 236 2624 38 3608 1202 1866 1094 2616 2223 4774 4989 4554 2586 724 3428 1990 43...
output:
824005
result:
wrong answer 1st lines differ - expected: '824766', found: '824005'