Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- ll int n, m, p;
- cin>>n>>m>>p;
- vector<ll int> a(n), b(m);
- for(auto &e: a) cin>>e;
- for(auto &e: b) cin>>e;
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- ll int tot = accumulate(b.begin(), b.end(), 0ll);
- ll int ans = 0;
- ll int cnt = 0;
- for(int i=0, j=m-1; i<n; i++)
- {
- while(j>=0 && b[j]+a[i]>=p)
- {
- tot -= b[j];
- j--;
- cnt++;
- }
- ans += a[i]*(m-cnt) + tot + cnt*p;
- }
- cout<<ans<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment