题目链接

题意

给出一个长度为\(n\)的序列\(a\),要求分为恰好\(K\)段。第\(i\)个点的贡献是\(a_i \times f(i)\),\(f(x)\)表示x所属的是第几段。

思路

非常巧妙的一个思路。

先让每个元素都选K遍。然后不断的删除。

具体做法就是,先求一遍前缀和。然后找出前缀和最小的\(K-1\)个前缀,将其从答案中减去。初始答案为所有元素和\(\times K\)

这样被减j遍的元素就位于第\(K-j\)段中。因为是前缀和。所以前边点被减的次数一定大于等于后边。然后就符合题意了。

代码

/*
* @Author: wxyww
* @Date: 2019-06-06 07:50:48
* @Last Modified time: 2019-06-06 07:56:06
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 300000 + 100;
ll read() {
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
ll a[N];
int main() {
int n = read(),K = read();
for(int i = 1;i <= n;++i) a[i] = read() + a[i - 1];
ll ans = a[n] * K;
sort(a + 1,a + n);
for(int i = 1;i <= K - 1;++i) ans -= a[i];
cout<<ans;
return 0;
}

CF1175D Array Splitting的更多相关文章

  1. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  2. Codeforces 754A Lesha and array splitting (搜索)

    题目链接 Lesha and array splitting 设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可. #includ ...

  3. Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting 水题

    C. Array Splitting You are given a sorted array

  4. 【codeforces 754A】Lesha and array splitting

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. CodeForces - 1175D Array Splitting(数组划分+后缀和+贪心)

    You are given an array a1,a2,…,ana1,a2,…,an and an integer kk. You are asked to divide this array in ...

  6. D. Array Splitting(后缀数组)

    You are given an array

  7. cf754 A. Lesha and array splitting

    应该是做麻烦了,一开始还没A(幸好上一次比赛水惨了) #include<bits/stdc++.h> #define lowbit(x) x&(-x) #define LL lon ...

  8. Codeforces Round #390 (Div. 2) A. Lesha and array splitting

    http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...

  9. Codeforce 1175 D. Array Splitting

    新鲜热乎的题 Codeforce 1175 D. 题意:给出一个长度为$n$的序列$a$,你需要把它划分为$k$段,每一个元素都需要刚好在其中一段中.分好之后,要计算$\sum_{i=1}^{n} ( ...

随机推荐

  1. 生活点滴:java基础知识细化

    生活点滴:java基础知识细化 一.前言 越是对一门语言深入了解,就会发现自己不知道的东西越多,这才是走向了正道,同样的,对于java语言特性的学习,笔者也只是初窥门径. 二.java基础知识思考 i ...

  2. Jenkins安装第一个插件和通过离线安装包进行安装

    1.打开左侧Manage Jenkins 选择Manage Plugins菜单 2.搜索Folders插件,该插件用于创建一个目录 3.点击安装进入插件安装状态,Jenkins会自动下载相关联的插件 ...

  3. 阿里开源 Dragonwell JDK 重磅发布 GA 版本:生产环境可用

    今年 3 月份,阿里巴巴重磅开源 OpenJDK 长期支持版本 Alibaba Dragonwell的消息,在很长一段时间内都是开发者的讨论焦点,该项目在 Github 上的 Star 数迅速突破 1 ...

  4. 云原生生态周报 Vol. 14 | K8s CVE 修复指南

    业界要闻 Mesosphere 公司正式更名为 D2IQ, 关注云原生. Mesosophere 公司日前发布官方声明正式更名为:D2iQ(Day-Two-I-Q),称关注点转向 Kubernetes ...

  5. ssl与ssh

    openssl genrsa -out private_key.pem 1024 ssh-keygen -t rsa -C zzf073@163.com ssl是安全会话协商机制: ssh是安全访问机 ...

  6. 服务器部署Laravel

    安装lnmp环境 参考:简书 - Centos 7 下安装LNMP官方最新版 安装redis 参考:简书 - Centos 7下使用yum安装redis 安装nodejs npm nodejs分8.x ...

  7. Asp.net HttpContext 简介

    1.  Context    名词解析      Context 直接翻译就是上下文."上下文" 这个名词还是挺让人费解的,是一个非常泛化的概念.刚看到有点让人摸不着头脑,一个高端 ...

  8. AspNetCore.Identity详解1——入门使用

    今年在面试的时候被问到单点登录的知识,当时支支吾吾不知该如何作答,于是面试失败.回到住所便开始上网查找资料,但苦于难于找到详尽的demo,总是无法入门.又由于我正在学习了解asp.net core,里 ...

  9. c#之添加window服务(定时任务)

    本文讲述使用window服务创建定时任务 1.如图,新建项目,windows桌面->windows服务 2.如图,右键,添加安装程序 3.在下图安装程序 serviceInstaller1 上右 ...

  10. js变量类型及检查

    一.变量的类型 JavaScript 有六种数据类型.主要的类型有 Number.String.object 以及 Boolean 类型,其他两种类型为 null 和 undefined.var ob ...