Ankit_132

D

Sep 23rd, 2023
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7.  
  8. int main()
  9. {
  10.     ll int n, m, p;
  11.     cin>>n>>m>>p;
  12.  
  13.     vector<ll int> a(n), b(m);
  14.     for(auto &e: a)     cin>>e;
  15.     for(auto &e: b)     cin>>e;
  16.  
  17.     sort(a.begin(), a.end());
  18.     sort(b.begin(), b.end());
  19.  
  20.     ll int tot = accumulate(b.begin(), b.end(), 0ll);
  21.  
  22.     ll int ans = 0;
  23.     ll int cnt = 0;
  24.  
  25.     for(int i=0, j=m-1; i<n; i++)
  26.     {
  27.         while(j>=0 && b[j]+a[i]>=p)
  28.         {
  29.             tot -= b[j];
  30.             j--;
  31.             cnt++;
  32.         }
  33.  
  34.         ans += a[i]*(m-cnt) + tot + cnt*p;
  35.     }
  36.  
  37.     cout<<ans<<"\n";
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment