当前位置:网站首页>[cf] 797 div3 E. Price Maximization
[cf] 797 div3 E. Price Maximization
2022-06-09 21:06:00 【*DDL_ GzmBlog】
Preface
Portal :
The question :
Given n n n Parcel , Two parcels merged , Its value is the sum of two numbers except k, Find the maximum value after merging all packages
Ideas :
Consider not merging first , So the value of each package is a [ i ] / k a[i]/k a[i]/k
Then we greedily consider merging , Take the rest of these packages and put them into the bucket , Find the double pointer Can match and Own and own
code :
int a[N],cnt[N];
int n,k;
void solve(){
ll res = 0;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
cnt[a[i]%k]++;// Barrel storage
res += a[i]/k;
}
int sum = 0;
for(int i=1 , j = k-1 ;i<=j ;i ++ ,j -- ){
sum += cnt[j];
if(i == j) break;
// Bound by the less
int t = min(sum,cnt[i]);
res +=t;
sum -=t;
}
// /2 Because Two in each group
cout<<res+sum/2<<endl;
for(int i=1;i<=n;i++) cnt[a[i]%k] -- ;// Empty
}
int main(){
int t;cin>>t;while(t--)
solve();
return 0 ;
}
边栏推荐
- GameFi新的启程,AQUANEE将于6.9日登陆Gate以及BitMart
- Examples of operator overloading in C #
- Sequence traversal of binary tree
- Gbase8s database select clause 4
- 瀏覽器無法打開百度,別的可以正常打開
- Mysql:1062 Duplicate entry '1' for key 'PRIMARY'
- Using ArrayList to lose data in multithreaded scenarios
- Why rewrite equals and hashcode?
- Share 4 methods of JS deep copy
- Perfect number (arithmetic borrow problem)
猜你喜欢

Problems and solutions of VFP accessing Oracle under 64 bit win10 environment

mmdetection训练自己的COCO数据集及常见问题

Sequence traversal of binary tree

排序-快速排序

二叉树的层序遍历
Who says redis can't save big keys

Set up ngrok server, realize intranet penetration service, and realize online access from external network to internal network

Sort - quick sort

从源码解析flutter_redux 的精准局部刷新

The browser cannot open Baidu, and others can be opened normally
随机推荐
Deploy kubernetes + kubevirt and basic use of kubevirt
minikube config set driver kvm2
SoFlu 软件机器人:辅助企业落地 DevOps 的自动化工具
Tke builds efk log service
Es automatic stop
Application of commission in C #
Gbase8s database select clause 4
C # learning about abstract classes
CompareTo和compare的区别
逻辑回归总结
Gbase8s database select clause 5
Huawei announced the establishment of three corps and two system departments, and has established 20 Corps in total
Mysql:1062 Duplicate entry '1' for key 'PRIMARY'
Mysql:1062 Duplicate entry '1' for key 'PRIMARY'
线性回归总结
Some problems encountered in deploying cinder CSI plugin
Lambda Exception
Keyword usage of default in C #
MediaTek: the market demand will not disappear, and the compound annual growth rate of revenue in the next three years will exceed 14%
739. daily temperature force deduction (monotonic decreasing stack)