#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define chkmin(a, b) a = min(a, b)
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const ll infinity = 1e18;
int main() {
int n, m;
cin >> n >> m;
vi dig1(m + n - 1), dig2(n + m - 1);
ll sum2 = 0, sum1 = 0;
for (int i = 0; i < m + n - 1; i++) {
cin >> dig2[i];
sum2 += dig2[i];
}
for (int i = 0; i < n + m - 1; i++) {
cin >> dig1[i];
sum1 += dig1[i];
}
ll sum = 0;
for (int i = 0; i < 2 * n - 1; i += 2) sum += dig1[i];
ll ans1 = sum;
for (int i = 0; i <= n; i += 2) {
sum -= dig1[i] + dig1[2 * n - i - 2];
if (i == n - 1) sum += dig1[i];
sum += dig2[i + n - 1] + dig2[n - i - 1];
if (!i) {
sum -= dig2[n - 1];
}
chkmin(ans1, sum);
}
sum = 0;
for (int i = 1; i < 2 * n - 1; i += 2) sum += dig1[i];
ll ans2 = sum;
for (int i = 1; i <= n; i += 2) {
sum -= dig1[i] + dig1[2 * n - i - 2];
if (i == n - 1) sum += dig1[i];
sum += dig2[i + n - 1] + dig2[n - i - 1];
if (!i) {
sum -= dig2[n - 1];
}
chkmin(ans2, sum);
}
cout << ans1 + ans2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
177 ms |
3456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
382 ms |
6476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |