【贪心】【快速幂】牛客模拟赛#2 C-涨薪

链接

题目描述

在这里插入图片描述

样例输入 #1

2 1 1 1
5 3

样例输出 #1

21

样例输入 #2

2 2 0 0
5 2

样例输出 #2

0

数据范围或提示

在这里插入图片描述

思路

显然我们选择最大的 X X X个翻三倍,其余的 Y Y Y个翻两倍,剩下的评C
那么我们求快速幂就好了
只不过如果m = 1的情况,要把C的也加进去

代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long

using namespace std;

const int tjh = 1e9 + 7;//%大佬
int n, m, X, Y, suma, sumb;
int a[100005];

bool cmp(int x, int y)
{return x > y;}

int ksm(int x, int p)
{
	int ans = 1;
	x %= tjh;
	while(p)
	{
		if (p & 1) ans = (ll)ans * x % tjh; 
		x = (ll)x * x % tjh;
		p >>= 1;
	}
	return ans % tjh;
}//快速幂

int main()
{
	scanf("%d%d%d%d", &n, &m, &X, &Y);
	int w1 = ksm(3, m);
	int w2 = ksm(2, m);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1; i <= X; ++i)
		suma = (suma + a[i]) % tjh;
	for (int j = X + 1; j <= X + Y; ++j)
		sumb = (sumb + a[j]) % tjh;
	int ansx = (((ll)suma * w1) % tjh + ((ll)sumb * w2) % tjh) % tjh;
	if (m == 1) 
		for (int i = X + Y + 1; i <= n; ++i)
			ansx = (ansx + a[i]) % tjh;
	printf("%d", ansx);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值