/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 43ms 1.027 MiB
#5 Accepted 18ms 932.0 KiB
#6 Accepted 19ms 952.0 KiB
#7 Accepted 2ms 576.0 KiB
#8 Accepted 17ms 2.02 MiB
#9 Accepted 17ms 2.066 MiB

Code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dt = array<int, 2>;

void test() {
  int n;
  cin >> n;

  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }

  ll tot = 0;
  for (int i = n - 2; i >= 0; i--) {
    b[i] = max(b[i], b[i + 1]);
  }

  for (int i = 0; i < n; i++) {
    if (a[i] <= b[i]) {
    	tot += b[i] - a[i];
    }
  }

  cout << tot << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;  
  cin >> T;
  for (int i = 1; i <= T; i++) {
    test();
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1228 Business Strategy
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 16:40:43
Judged At
2025-09-02 16:40:43
Judged By
Score
100
Total Time
43ms
Peak Memory
2.066 MiB