当前位置:   article > 正文

codeforcs1165E. Two Arrays and Sum of Functions 贪心

two arrays and sum of function

题目链接 琪亚娜世界第一可爱

给出两个数组,对数组B重新排序,记数组C[i]=A[i]*B[i],求C所有子区间的和的最小值。


给定区间长度,C中元素对答案的贡献只与位置有关,也就是对于位置i来说,在后续的计算中,这个元素出现的次数只与位置有关。
所以可以提前计算出现的次数num[i],并记C[i]=A[i]*num[i],找C中最大的元素和B中最小的元素相乘就是答案。
由于计算最小的值,而不是最小的余数,所以在计算C[i]的过程中不能求余,只能在计算ans是求余。

而我错的就比较厉害了,cmp参数列表都是int。。。


#pragma GCC diagnostic error "-std=c++11"
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
#define Pair pair<int,int>
#define re return

#define getLen(name,index) name[index].size()
#define mem(a,b) memset(a,b,sizeof(a))
#define Make(a,b) make_pair(a,b)
#define Push(num) push_back(num)
#define rep(index,star,finish) for(register int index=star;index<finish;index++)
#define drep(index,finish,star) for(register in
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/503211
推荐阅读
相关标签
  

闽ICP备14008679号