Educational Codeforces Round 30 A[水题/数组排序]
2 seconds
256 megabytes
standard input
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.
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.
Print one number — minimum time Luba needs to do all n chores.
4 2 2
3 6 7 10
13
5 2 1
100 100 100 100 100
302
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[];
while(~scanf("%d%d%d",&n,&k,&x))
{
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
int sum=;
for(int i=;i<n-k;i++)
{
sum+=a[i];
}
for(int i=n-k+;i<=n;i++)
{
sum+=x;
}
printf("%d\n",sum);
}
return ;
}
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
x=;int f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch))x=x*+ch-'',ch=getchar();
x*=f;
}
inline void readLong(ll &x) {
x=;int f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch))x=x*+ch-'',ch=getchar();
x*=f;
}
/*================Header Template==============*/
int n,a,ans=,k,x;
int main() {
readInt(n);
readInt(k);
readInt(x);
for(int i=;i<=n;i++) {
readInt(a);
if(i<=n-k)
ans+=a;
else
ans+=x;
}
printf("%d\n",ans);
return ;
}
朋友的
Educational Codeforces Round 30 A[水题/数组排序]的更多相关文章
- Educational Codeforces Round 30
Educational Codeforces Round 30 A. Chores 把最大的换掉 view code #pragma GCC optimize("O3") #pr ...
- Educational Codeforces Round 23 A-F 补题
A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...
- Educational Codeforces Round 30 B【前缀和+思维/经典原题】
B. Balanced Substring time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 24 A 水 B stl C 暴力 D stl模拟 E 二分
A. Diplomas and Certificates time limit per test 1 second memory limit per test 256 megabytes input ...
- Educational Codeforces Round 12 B C题、
B. Shopping 题意:n个顾客,每个顾客要买m个物品,商场总共有k个物品,看hint就只知道pos(x)怎么算了,对于每一个Aij在k个物品中找到Aij的位置.然后加上这个位置对于的数值,然后 ...
- Educational Codeforces Round 10 A B题、
A. Gabriel and Caterpillar 题意: 就是说 一个小孩子去观察毛毛虫从 h1的地方爬到h2的地方.毛毛虫从10点爬到22点.每小时爬的距离是a, 晚上22点到第二天早上10点 ...
- Educational Codeforces Round 30 D. Merge Sort
题意:给你n和k,n代表有多少个数,k代表几次操作,求一个1到n的序列,要k次mergesort操作才能还原 Examples Input 3 3 Output 2 1 3 Input 4 1 Out ...
- Educational Codeforces Round 5
616A - Comparing Two Long Integers 20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...
- Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
随机推荐
- HTML5<canvas>标签:使用canvas元素在网页上绘制四分之一圆(3)
前几天自己做了个四分之一的圆,放到手机里面测试.效果不是很好.于是今天通过查资料,找到了canvas.自己研究了一天,发现可以使用canvas画圆.代码如下: <!doctype html> ...
- C语言指针大杂烩
By francis_hao Oct 31,2016 指针数组和数组指针 指针数组本身是个数组,数组的内容是指针.形如char *pa[].由于[]优先级高于*,pa先于[]结合表示pa是一个数组,p ...
- poj 1523 割点 tarjan
Description Consider the two networks shown below. Assuming that data moves around these networks on ...
- zigbee芯片 - JN5169
http://www.nxp.com/products/wireless-connectivity/2.4-ghz-wireless-solutions/support-resources-for-j ...
- Python之日志操作(logging)
import logging 1.自定义日志级别,日志格式,输出位置 logging.basicConfig( level=logging.DEBUG, format='%(asctime)s | ...
- js获取当前url地址参数中文乱码问题
网上看了一些关于此问题的文章,都说的不清不楚,有些更是乱七八糟,完全没法看,故此找了一篇能用的,借鉴作为笔记. //首先获取到当前页面的地址栏信息 var url = window.location. ...
- 51Nod 1118 机器人走方格--求逆元
(x/y) %mod =x*(y^(mod-2))%mod; 在算x,y的时候可以一直mod 来缩小 y^(mod-2)显然是个快速幂 #include <iostream> #inclu ...
- ecma 2018, javascript spread syntax behaves like Object.assign
as the subject. It is only supported in Chrome version 60+, so, first check the version, or just use ...
- POJ 1002 487-3279 (map )
title: 487-3279 map POJ1002 tags: [map] 题目链接 Description Businesses like to have memorable telephone ...
- 在Xcode6中搭建Python开发环境
http://jingyan.baidu.com/article/f71d60379c73001ab741d14e.html 对于使用Mac电脑,刚入门Python的同学,一定很好奇是不是可以使用Xc ...