#include #include using namespace std; int main() { int N, r = 0, l = 0, max = 0;; cin >> N; vector A(2 * N); for (int i = 0;i < 2 * N;i++) { cin >> A[i]; } for (int i = 0;i < N;i++) { if (A[2 * l] - A[2 * l + 1] >= A[2 * N -1 - 2 * r] - A[2 * N -1 - 2 * r - 1]) { max += A[2 * l] - A[2 * l + 1]; l++; } else if (A[2 * l] - A[2 * l + 1] < A[2 * N - 1 - 2 * r] - A[2 * N - 1 - 2 * r - 1]) { max += A[2 * N - 1 - 2 * r] - A[2 * N - 1 - 2 * r - 1]; r++; } } cout << max; }