Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- #define itloop(it,x) for(auto it=x.begin();it!=x.end();it++)
- #define reloop(i,e,b) for(auto i=e;i>=b;i--)
- #define loop(i,b,e) for(auto i=b;i<=e;i++)
- #define ALL(x) x.begin(),x.end()
- #define SZ(x) x.size()
- #define PB push_back
- #define MP make_pair
- #define F first
- #define S second
- typedef long long LL;
- typedef vector<int> VI;
- typedef long long LL;
- typedef vector<int> VI;
- bool compare(const std::pair<int, int>&i, const std::pair<int, int>&j) {
- return abs(i.first-i.second) > abs(j.first - j.second);
- }
- pair<int,int> t[1001];
- int n,k1,k2;
- int main() {_
- cin >> n >> k1 >> k2;
- loop(i,0,n-1)
- cin >> t[i].F;
- loop(i,0,n-1)
- cin >> t[i].S;
- while(k1 > 0 || k2 > 0) {
- sort(t,t+n,compare);
- if(k1 > 0 && k2 > 0) {
- if(t[0].F > t[0].S)
- t[0].F--,t[0].S++;
- else if(t[0].F < t[0].S)
- t[0].F++,t[0].S--;
- else {
- k1 = 0;
- k2 = 0;
- }
- k1--;
- k2--;
- }
- else if(k1 > 0 && k2 == 0) {
- if(t[0].F > t[0].S)
- t[0].F--;
- else if(t[0].F < t[0].S)
- t[0].F++;
- else {
- k1 = 0;
- k2 = 0;
- }
- k1--;
- }
- else if(k1 == 0 && k2 > 0) {
- if(t[0].S > t[0].F)
- t[0].S--;
- else if(t[0].S < t[0].F)
- t[0].S++;
- else {
- k1 = 0;
- k2 = 0;
- }
- k2--;
- }
- }
- /* loop(i,0,n-1)
- printf("%d ",t[i].F);
- printf("\n");
- loop(i,0,n-1)
- printf("%d ",t[i].S);*/
- LL ans=0;
- loop(i,0,n-1)
- ans += (LL)abs(t[i].F-t[i].S)*(LL)abs(t[i].F-t[i].S);
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement