fork(1) download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ii pair <int, int>
  4. #define F first
  5. #define S second
  6. #define pb push_back
  7.  
  8. using namespace std;
  9.  
  10. const int N = 2e5 + 5;
  11. const int mod = 1e9 + 7;
  12.  
  13. int n, a[N], b[N];
  14.  
  15. void solve(){
  16. cin >> n;
  17. ll ans = 0;
  18. int mx = 0;
  19. set <ii> s;
  20. s.insert(ii(-2e9, -2e9));
  21. s.insert(ii(2e9, 2e9));
  22. for (int i = 1; i <= n; ++ i) cin >> a[i];
  23. for (int i = 1; i <= n; ++ i){
  24. cin >> b[i];
  25. ans += (a[i] - b[i]);
  26.  
  27. int l = b[i], r = a[i];
  28.  
  29. ii st = *(--s.upper_bound(ii(b[i], b[i])));
  30. if (st.S >= b[i]){
  31. l = min(l, st.F);
  32. s.erase(s.lower_bound(st));
  33. r = max(r, st.S);
  34. }
  35.  
  36. while (true){
  37. ii ed = *s.lower_bound(ii(b[i], b[i]));
  38. if (ed.F > a[i]) break;
  39. r = max(r, ed.S);
  40. l = min(l, ed.F);
  41. s.erase(s.lower_bound(ed));
  42. }
  43. s.insert(ii(l, r));
  44. mx = max(mx, r - l);
  45. cout << ans - mx << ' ';
  46. }
  47.  
  48. cout << '\n';
  49. }
  50.  
  51. int main(){
  52. // freopen(".inp", "r", stdin);
  53. // freopen(".out", "w", stdout);
  54. ios_base::sync_with_stdio(0);
  55. cin.tie(0);
  56. cout.tie(0);
  57. int t;
  58. cin >> t;
  59. while (t --) solve();
  60.  
  61. return 0;
  62. }
  63.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
Main.java:2: error: illegal character: '#'
#define ll long long
^
Main.java:3: error: illegal character: '#'
#define ii pair <int, int>
^
Main.java:4: error: illegal character: '#'
#define F first
^
Main.java:5: error: illegal character: '#'
#define S second
^
Main.java:6: error: illegal character: '#'
#define pb push_back
^
Main.java:10: error: class, interface, or enum expected
const int N = 2e5 + 5;
^
Main.java:11: error: class, interface, or enum expected
const int mod = 1e9 + 7;
^
Main.java:13: error: class, interface, or enum expected
int n, a[N], b[N];
^
Main.java:15: error: class, interface, or enum expected
void solve(){
^
Main.java:17: error: class, interface, or enum expected
    ll ans = 0;
    ^
Main.java:18: error: class, interface, or enum expected
    int mx = 0;
    ^
Main.java:19: error: class, interface, or enum expected
    set <ii> s;
    ^
Main.java:20: error: class, interface, or enum expected
    s.insert(ii(-2e9, -2e9));
    ^
Main.java:21: error: class, interface, or enum expected
    s.insert(ii(2e9, 2e9));
    ^
Main.java:22: error: class, interface, or enum expected
    for (int i = 1; i <= n; ++ i) cin >> a[i];
    ^
Main.java:22: error: class, interface, or enum expected
    for (int i = 1; i <= n; ++ i) cin >> a[i];
                    ^
Main.java:22: error: class, interface, or enum expected
    for (int i = 1; i <= n; ++ i) cin >> a[i];
                            ^
Main.java:23: error: class, interface, or enum expected
    for (int i = 1; i <= n; ++ i){
    ^
Main.java:23: error: class, interface, or enum expected
    for (int i = 1; i <= n; ++ i){
                    ^
Main.java:23: error: class, interface, or enum expected
    for (int i = 1; i <= n; ++ i){
                            ^
Main.java:25: error: class, interface, or enum expected
        ans += (a[i] - b[i]);
        ^
Main.java:27: error: class, interface, or enum expected
        int l = b[i], r = a[i];
        ^
Main.java:29: error: class, interface, or enum expected
        ii st = *(--s.upper_bound(ii(b[i], b[i])));
        ^
Main.java:30: error: class, interface, or enum expected
        if (st.S >= b[i]){
        ^
Main.java:32: error: class, interface, or enum expected
            s.erase(s.lower_bound(st));
            ^
Main.java:33: error: class, interface, or enum expected
            r = max(r, st.S);
            ^
Main.java:34: error: class, interface, or enum expected
        }
        ^
Main.java:38: error: class, interface, or enum expected
            if (ed.F > a[i]) break;
            ^
Main.java:39: error: class, interface, or enum expected
            r = max(r, ed.S);
            ^
Main.java:40: error: class, interface, or enum expected
            l = min(l, ed.F);
            ^
Main.java:41: error: class, interface, or enum expected
            s.erase(s.lower_bound(ed));
            ^
Main.java:42: error: class, interface, or enum expected
        }
        ^
Main.java:44: error: class, interface, or enum expected
        mx = max(mx, r - l);
        ^
Main.java:45: error: class, interface, or enum expected
        cout << ans - mx << ' ';
        ^
Main.java:46: error: class, interface, or enum expected
    }
    ^
Main.java:49: error: class, interface, or enum expected
}
^
Main.java:55: error: class, interface, or enum expected
    cin.tie(0);
    ^
Main.java:56: error: class, interface, or enum expected
    cout.tie(0);
    ^
Main.java:57: error: class, interface, or enum expected
    int t;
    ^
Main.java:58: error: class, interface, or enum expected
    cin >> t;
    ^
Main.java:59: error: class, interface, or enum expected
    while (t --) solve();
    ^
Main.java:61: error: class, interface, or enum expected
    return 0;
    ^
Main.java:62: error: class, interface, or enum expected
}
^
45 errors
stdout
Standard output is empty