/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 676.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 20ms 1.277 MiB
#5 Accepted 18ms 1.238 MiB
#6 Accepted 40ms 1.184 MiB
#7 Accepted 2ms 532.0 KiB
#8 Accepted 20ms 2.77 MiB
#9 Accepted 19ms 2.77 MiB

Code

// @rakibul-islam

#include "bits/stdc++.h"
using namespace std;

using ll = long long;
const ll oo = 1e17;

void solve() {
  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];
  vector<ll> suf(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    suf[i] = max(suf[i + 1], b[i]);
  }
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += max(0LL, suf[i] - a[i]);
  }
  cout << sum << "\n";
} 

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;  cin >> t;
  for (int test = 1; test <= t; test++) {
    solve();
  }
  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:33:41
Judged At
2025-09-02 16:33:41
Judged By
Score
100
Total Time
40ms
Peak Memory
2.77 MiB