147862025-02-02 16:53:21sarminVásárlás (75 pont)cpp17Wrong answer 6/7520ms1612 KiB
// Created by Armin on 2/1/2025.

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<int, int>;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n; cin >> n;
    vector<int> a(n), b(n);
    int sumb = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> ba(n);
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      sumb += b[i];
      ba[i] = b[i] - a[i];
    }

    int i = 0, j = 0, sum = 0;
    int maxi = 0, maxj = 0, maxsum = 0;
    while (i + 1 < n && j + 1 < n) {
      if (sum + ba[j] < 0) {
        j++;
        i = j;
        sum = ba[i];
      } else {
        sum += ba[j];
        j++;
      }
      if (sum > maxsum) {
        maxsum = sum;
        maxi = i;
        maxj = j;
      }
    }
    int c = 0, d = 0;
    for (int k = maxi; k <= maxj; k++) {
      c += a[k];
      d += b[k];
    }
    cout << c + sumb - d << '\n';
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/75
1Accepted0/01ms316 KiB
2Wrong answer0/010ms828 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/41ms316 KiB
5Wrong answer0/41ms316 KiB
6Wrong answer0/41ms316 KiB
7Wrong answer0/41ms316 KiB
8Wrong answer0/31ms316 KiB
9Wrong answer0/41ms316 KiB
10Wrong answer0/41ms316 KiB
11Wrong answer0/41ms320 KiB
12Wrong answer0/51ms316 KiB
13Wrong answer0/319ms1588 KiB
14Wrong answer0/319ms1480 KiB
15Wrong answer0/319ms1484 KiB
16Wrong answer0/319ms1588 KiB
17Wrong answer0/320ms1588 KiB
18Wrong answer0/319ms1612 KiB
19Accepted3/319ms1612 KiB
20Accepted3/319ms1588 KiB
21Wrong answer0/319ms1480 KiB
22Wrong answer0/317ms1576 KiB
23Wrong answer0/320ms1588 KiB
24Wrong answer0/319ms1480 KiB