Advertisement
MinhNGUYEN2k4

Untitled

Jan 16th, 2022
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. main(){
  5.     ios_base::sync_with_stdio(false);cin.tie(0);
  6.     if(fopen(".inp","r")){freopen(".inp","r",stdin);freopen(".out","w",stdout);}
  7.     bool mUlTiTeStCasE=1;
  8.     int tt=1;
  9.     if(mUlTiTeStCasE)cin>>tt;
  10.     auto proc=[]()->void{
  11.         int n;
  12.         cin>>n;
  13.         int k[n],h[n];
  14.         pair<int,int>f[n];
  15.         for(int i=0;i<n;++i)cin>>k[i];
  16.         for(int i=0;i<n;++i)cin>>h[i],f[i]=pair<int,int>(k[i]-h[i]+1,k[i]);
  17.         auto sum=[](int l,int r)->int{
  18.             return (r-l+1)*(l+r)>>1;
  19.         };
  20.         sort(f,f+n);
  21.         int ds=0,damge=0,time=0;
  22.         for(int i=0;i<n;++i){
  23.             if(time>=f[i].second)continue;
  24.             if(f[i].first>time){
  25.                 ds+=sum(1,f[i].second-f[i].first+1);
  26.                 damge=f[i].second-f[i].first+1;
  27.                 time=f[i].second;
  28.             }
  29.             else{
  30.                 f[i].first=time+1;
  31.                 ds+=sum(damge+1,damge+1+f[i].second-f[i].first);
  32.                 damge+=f[i].second-f[i].first+1;
  33.                 time=f[i].second;
  34.             }
  35.         }
  36.         cout<<ds<<'\n';
  37.     };
  38.     while(tt--){
  39.         proc();
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement