当前位置:网站首页>Minimize the error
Minimize the error
2022-07-02 00:56:00 【Learning KL & TK】
Problem - B - Codeforces
https://codeforces.com/contest/960/problem/B The title means to give you The length is n , a Array k1 operations ,b Array k2 operations
Each operation can +1 or -1
Their thinking
Put every a and b The pairing value of is calculated first , The question should be the square of the absolute value , Because we need to make the answer smaller , Reducing the large absolute value can make the final total result smaller , Then priority queue can be used to solve this problem
#include"bits/stdc++.h"
#define ll long long
#define pi pair<int,int>
#define inf 0x3f3f3f3f
#define _for(i,a,b) for(int i=a;i<=b;i++)
#define for_(i,a,b) for(int i=a;i<b;i++)
#define _fr(i,a,b) for(int i=a;i>=b;i--)
#define fr_(i,a,b) for(int i=a;i>b;i--)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e3+5;
const ll mod = 1e9+7;
const double lp=1.000000011;
map<char,int>mp;
int n,m,d,t;
priority_queue<ll,vector<ll>,less<ll>>q;
void solve(){
int k1,k2;
cin >> n >> k1 >> k2;
vector<int>a(n),b(n),c(n);
for_(i,0,n) cin >> a[i];
for_(i,0,n){
cin >> b[i];
c[i]= abs(a[i]-b[i]);
q.push(c[i]);
}
int ans = k1+k2;
while (ans--){
int lo = q.top();
q.pop();
q.push(abs(lo-1));
}
ll sum = 0;
while (!q.empty()){
sum+=q.top()*q.top();
q.pop();
}
cout << sum << endl;
}
int main()
{
IOS;
solve();
return 0;
}边栏推荐
- Node -- egg creates a local file access interface
- Leetcode question brushing: stack and queue 07 (maximum value of sliding window)
- King combat power query renamed toolbox applet source code - with traffic main incentive advertisement
- 449-原码、补码、反码
- Summary of Aix storage management
- Excel PivotTable
- Collection: comprehensive summary of storage knowledge
- 【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)
- S32Kxxx bootloader之UDS bootloader
- Global and Chinese markets for power over Ethernet (POE) solutions 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
![[eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)](/img/0d/22f3f65ab9422383df9a55d0724d59.jpg)
[eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)

JS -- image to base code, base to file object

2022 pinduoduo details / pinduoduo product details / pinduoduo SKU details

Creation of volume group for AIX storage management (I)

Leetcode question brushing: stack and queue 07 (maximum value of sliding window)

To meet the needs of consumers in technological upgrading, Angel water purifier's competitive way of "value war"

2023 Lexus ES products have been announced, which makes great progress this time

Leetcode skimming: binary tree 02 (middle order traversal of binary tree)

Take the enclave Park as a sample to see how Yuhua and Shaoshan play the song of Chang Zhu Tan integrated development

Otaku wallpaper Daquan wechat applet source code - with dynamic wallpaper to support a variety of traffic owners
随机推荐
Leetcode skimming: binary tree 02 (middle order traversal of binary tree)
Global and Chinese markets for maritime services 2022-2028: Research Report on technology, participants, trends, market size and share
Take the enclave Park as a sample to see how Yuhua and Shaoshan play the song of Chang Zhu Tan integrated development
2022 high altitude installation, maintenance and removal of test question simulation test platform operation
AIX存储管理之卷组属性的查看和修改(二)
Global and Chinese market of picture archiving and communication system (PACS) 2022-2028: Research Report on technology, participants, trends, market size and share
AIX存储管理之卷组的创建(一)
2023款雷克萨斯ES产品公布,这回进步很有感
Promise and modular programming
Node -- add compressed file
Global and Chinese market of collaborative applications 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode question brushing: stack and queue 07 (maximum value of sliding window)
Node——添加压缩文件
Otaku wallpaper Daquan wechat applet source code - with dynamic wallpaper to support a variety of traffic owners
[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login
UDS bootloader of s32kxxx bootloader
Excel PivotTable
什么是商业养老保险?商业养老保险安全靠谱吗?
JS -- image to base code, base to file object
You probably haven't noticed the very important testing strategy in your work