#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100000;
alignas(1024) int a[MAXN], b[MAXN], dp[MAXN];
signed main(){
cin.tie(0)->sync_with_stdio(0);
int h, w; cin >> h >> w;
for (int i=0; i<h; i++){
cin >> a[i];
}
for (int j=0; j<w; j++){
cin >> b[j];
}
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
for (int i=0; i<h-1; i++){
int v = dp[0];
for (int j=1; j<w; j++){
v = v > dp[j] - a[i] * j ? dp[j] - a[i] * j : v;
dp[j] = dp[j] < v + a[i] * j ? dp[j] : v + a[i] * j;
}
for (int j=0; j<w; j++){
dp[j] += b[j];
}
}
for (int j=1; j<w; j++){
dp[j] = dp[j] < dp[j-1] + a[h-1] ? dp[j] : dp[j-1] + a[h-1];
}
cout << dp[w-1] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
0 ms |
860 KB |
Output is correct |
3 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
744 KB |
Output is correct |
4 |
Correct |
790 ms |
1172 KB |
Output is correct |
5 |
Correct |
18 ms |
1116 KB |
Output is correct |
6 |
Correct |
3 ms |
856 KB |
Output is correct |
7 |
Execution timed out |
2052 ms |
1628 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
0 ms |
860 KB |
Output is correct |
3 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |