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] 总共两次询 ...
随机推荐
- Powershell快速入门
Powershell快速入门 来源: https://blog.csdn.net/u011054333/article/details/72567590 https://blog.csdn.net/u ...
- [Leetcode] scramble string 乱串
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- number 解题报告
number 题目描述 给定整数 \(m,k\),求出正整数 \(n\) 使得 \(n+1,n+2,-,2n\) 中恰好有 \(m\) 个数在二进制下恰好有 \(k\) 个 \(1\). 有多组数据. ...
- linux管理(二)---网络使用情况的监控
我们经常在监控服务器或者排查程序性能瓶颈时需要知道 网络带宽的使用情况,看看带宽是不是瓶颈. linux系统中监控网络的工具和命令很多. 但其实主要分2种,一种是实时监控带宽情况(速度如何),一种是 ...
- 模拟赛 yjqa
考场上怕是石乐志. 状态设计还是很自然的,求什么设什么. f[i]表示前i个人安排好,电梯最早回到0层的时间 转移的话,枚举上一次最后一个带走的是谁 f[i]=min(max(f[j],t[i])+2 ...
- Java并发编程--ThreadPoolExecutor
概述 为什么要使用线程池? 合理利用线程池能够带来三个好处.第一:降低资源消耗.通过重复利用已创建的线程降低线程创建和销毁造成的消耗.第二:提高响应速度.当任务到达时,任务可以不需要等到线程创建就能立 ...
- redis连接池自动释放
http://blog.itpub.net/29485627/viewspace-1977880/
- 【BZOJ2460】【BJOI2011】元素 [线性基]
元素 Time Limit: 20 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 相传,在远古时期,位于西方大陆的 Ma ...
- 【51NOD】1486 大大走格子
[算法]动态规划+组合数学 [题意]有一个h行w列的棋盘,定义一些格子为不能走的黑点,现在要求从左上角走到右下角的方案数. [题解] 大概能考虑到离散化黑点后,中间的空格子直接用组合数计算. 然后解决 ...
- bzoj 2705 数学 欧拉函数
首先因为N很大,我们几乎不能筛任何东西 那么考虑设s(p)为 gcd(i,n)=p 的个数,显然p|n的时候才有意义 因为i与n的gcd肯定是n的因数,所以那么可得ans=Σ(p*s(p)) 那么对于 ...