fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define yes cout << "YES\n"
  6. #define no cout << "NO\n"
  7. #define el "\n"
  8. #define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  9. #define fix(x) cout << fixed << setprecision(x)
  10. #define all(v) v.begin(), v.end()
  11.  
  12. void file()
  13. {
  14. #ifndef ONLINE_JUDGE
  15. freopen("input.txt", "r", stdin);
  16. freopen("output.txt", "w", stdout);
  17. #endif
  18. }
  19.  
  20. int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  21. int lcm(int a, int b) { return a / gcd(a, b) * b; }
  22. bool prime(int n) {
  23. if (n == 2) return true;
  24. if (n % 2 == 0 || n == 1) return false;
  25. for (int i = 3; i * i <= n; i += 2)
  26. if (n % i == 0) return false;
  27. return true;
  28. }
  29.  
  30. int32_t main()
  31. {
  32. Arwa
  33. int t=1;
  34. //cin>>t;
  35. while(t--)
  36. {
  37. int n,k1,k2;
  38. cin>>n>>k1>>k2;
  39. int a[n],b[n];
  40. for(int i=0;i<n;i++)
  41. cin>>a[i];
  42. for(int i=0;i<n;i++)
  43. cin>>b[i];
  44. for(int i=0;i<n;i++)
  45. a[i]=abs(a[i]-b[i]);
  46. sort(a,a+n);
  47. int ops=k1+k2,sum=0;
  48. for(int i=n-1;i>=0&&ops>0;i--)
  49. {
  50. if(ops-a[i]>=0)
  51. {
  52. ops-=a[i];
  53. a[i]=0;
  54. }
  55. else
  56. {
  57. a[i]-=ops;
  58. ops=0;
  59. }
  60. }
  61. for(int i=0;i<n;i++)
  62. sum+=a[i]*a[i];
  63. if(sum==0)
  64. cout<<min(ops,abs(k1-k2))<<el;
  65. else cout<<sum<<el;
  66. }
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
234