이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  vector<ll> cost1(n+m-1),cost2(n+m-1);
  for(int i = 0; i < n+m-1; ++i) cin >> cost1[i];
  for(int i = 0; i < n+m-1; ++i) cin >> cost2[i];
  ll p1 = 0,p2 = 0,i1 = 0,i2 = 0;
  int x = 0,y = m-1;
  for(int i = 0; i < n+m-1; ++i){
    if((x+y)&1) i1 += cost1[i];
    else p1 += cost1[i];
    if(y > 0) --y;
    else ++x;
  }
  x = 0,y = 0;
  for(int i = 0; i < n+m-1; ++i){
    if((x+y)&1) i2 += cost2[i];
    else p2 += cost2[i];
    if(x < n-1) ++x;
    else ++y;
  }
  ll ans = 0;
  if(p1 <= p2){
    ans += p1;
    if(m == n){
      if((n%2 == 0) and cost1[0] + cost1[n+m-2] > cost2[n-1]){
        ans += cost2[n-1] - cost1[0] - cost1[n+m-2];
      }
    }
    else{
      if((m%2 == 0) and cost1[0] > cost2[m-1]){
        ans += cost2[m-1] - cost1[0];
      }
      if((n%2 == 0) and cost1[n+m-2] > cost2[n-1]){
        ans += cost2[n-1] - cost1[n+m-2];
      }
    }
  }
  else{
    ans += p2;
    if(m == n){
      if(cost2[0] + cost2[n+m-2] > cost1[n-1]){
        ans += cost1[n-1] - cost2[0] - cost2[n+m-1];
      }
    }
    else{
      if(cost2[0] > cost1[m-1]){
        ans += cost1[m-1] - cost2[0];
      }
      if(((n+m)%2 == 0) and cost2[n+m-2] > cost1[n-1]){
        ans += cost1[n-1] - cost2[n+m-2];
      }
    }
  }
  if(i1 <= i2){
    ans += i1;
    if(m == n){
      if((n%2 == 1) and cost1[0] + cost1[n+m-2] > cost2[n-1]){
        ans += cost2[n-1] - cost1[0] - cost1[n+m-2];
      }
    }
    else{
      if((m%2 == 1) and cost1[0] > cost2[m-1]){
        ans += cost2[m-1] - cost1[0];
      }
      if((n%2 == 1) and cost1[n+m-2] > cost2[n-1]){
        ans += cost2[n-1] - cost1[n+m-2];
      }
    }
  }
  else{
    ans += i2;
    if(m != n){
      if(((n+m)%2 == 1) and cost2[n+m-2] > cost1[n-1]){
        ans += cost1[n-1] - cost2[n+m-2];
      }
    }
  }
  cout << ans;
  return 0;
}
| # | 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... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |