Educational Codeforces Round 30 A[水题/数组排序]

A. Chores
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Luba has to do n chores today. i-th chore takes ai units of time to complete. It is guaranteed that for every  the conditionai ≥ ai - 1 is met, so the sequence is sorted.

Also Luba can work really hard on some chores. She can choose not more than k any chores and do each of them in x units of time instead of ai ().

Luba is very responsible, so she has to do all n chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously.

Input

The first line contains three integers n, k, x (1 ≤ k ≤ n ≤ 100, 1 ≤ x ≤ 99) — the number of chores Luba has to do, the number of chores she can do in x units of time, and the number x itself.

The second line contains n integer numbers ai (2 ≤ ai ≤ 100) — the time Luba has to spend to do i-th chore.

It is guaranteed that , and for each  ai ≥ ai - 1.

Output

Print one number — minimum time Luba needs to do all n chores.

Examples
input
4 2 2
3 6 7 10
output
13
input
5 2 1
100 100 100 100 100
output
302
Note

In the first example the best option would be to do the third and the fourth chore, spending x = 2 time on each instead of a3 and a4, respectively. Then the answer is 3 + 6 + 2 + 2 = 13.

In the second example Luba can choose any two chores to spend x time on them instead of ai. So the answer is 100·3 + 2·1 = 302.

 

【分析】:***贪心。控制前n-k个数组求本位和,其他换成k求和。

【代码】:

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,x;
    int a[105];
    while(~scanf("%d%d%d",&n,&k,&x))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        int sum=0;
        for(int i=0;i<n-k;i++)
        {
            sum+=a[i];
        }
        for(int i=n-k+1;i<=n;i++)
        {
            sum+=x;
        }
        printf("%d\n",sum);
    }
    return 0;
}
View Code

 

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
    x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;
}
inline void readLong(ll &x) {
    x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;
}
/*================Header Template==============*/
int n,a,ans=0,k,x;
int main() {
    readInt(n);
    readInt(k);
    readInt(x);
    for(int i=1;i<=n;i++) {
        readInt(a);
        if(i<=n-k)
            ans+=a;
        else
            ans+=x;
    }
    printf("%d\n",ans);
    return 0;
} 
朋友的

 

全部评论

相关推荐

鸿雁于飞:1. 求职定位乱成一锅粥,直接劝退HR 你期望职位同时写了「项目经理/技术经理/交付经理」,这仨岗根本不是一个赛道!项目经理玩流程和干系人,技术经理玩架构和带技术团队,交付经理玩客户和回款,你仨全堆上,HR直接判定「这人自己都不知道自己要干啥,没核心竞争力」,直接扔简历。 ​ 2. 2年多的职业空窗期,一个字不提,纯纯自杀行为 金融行业最看重职业连贯性和背景干净,你2018年5月到2020年8月,整整2年3个月没上班,啥说明都没有!HR直接脑补你是不是有竞业限制、是不是创业失败、是不是有啥背调过不了的问题,直接不敢往下看,首轮就给你筛了,这是最致命的坑! ​ 3. 工作经历纯纯摆烂,干货全藏起来了 你每段工作就写个公司、职位、时间,干了啥、带了多大团队、出了啥核心成果、给公司赚了/省了多少钱,一个字没有,全堆到后面的项目里了。HR看简历就3秒,第一眼看不到你每段工作的价值,直接就划走了,根本不会翻你后面的项目。 ​ 4. 项目经验像个大杂烩,还全是bug 你堆了快10个项目,银行、证券、公安、政务、日本项目啥都有,跟个杂货铺一样,HR根本看不到你的核心优势在哪。而且项目连个起止时间都不写,谁知道你这是最近的标杆项目,还是10年前刚入行干的活?还有数据前后矛盾,一会说「零事故交付」,一会说「生产事故率降低50%」,HR一看就觉得你瞎包装,根本不信。 ​ 5. 15年经验的经理岗,还在写一线拧螺丝的活,层级完全错配 你都应聘经理级岗位了,简历里还在写自己写接口、写测试脚本、做前端开发这些一线执行的活,完全没写你怎么搭建管理体系、怎么带团队、怎么搞定甲方、怎么控项目风险、怎么拿经营结果,MBA的价值一点没体现出来。HR看完直接觉得:合着你干了15年,还是个高级开发,根本达不到经理岗的要求,直接pass。 ​ 6. AI风口完全没抓住,写了句空话等于没写 现在全行业都在卷AI+金融,人家招管理岗,都要能落地AI场景的人。你就写了句「深化Transformer与大模型底层技术研习」,纯纯空话,一点实际落地成果都没有,跟其他候选人比,完全没差异化优势,人家凭啥放着年轻能落地的不要,要你这个只学了理论的? 姐好好看看,然后改改简历吧,要专,要精,然后降低求职目标。希望你能早日拿到offer
点赞 评论 收藏
分享
天乐敲代码呀:9咋了,多投投优越感就没了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务