[NOI.AC] candy
题意:求净利益。
思路:
其实我也不怎么懂题面。
不过这种题一般来说就是从最大的开始选。
所以考虑贪心。
那么代价如何处理呢??
我们考虑两个序列同时选数,把代价每次记录到一个序列的和上,那么对于两次的净利益求最大即可。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const int maxn = 100010;
int a[maxn];
int b[maxn];
inline int solve(int *a,int *b,int n,int W) {
int sum_a = 0;
int sum_b = 0;
int ans = -999;
for(int i = 1,tmp = 0;i <= n; ++i) {
sum_a += a[i];
while(tmp <= n && sum_b < sum_a) {
sum_b += b[++tmp];
}
if(sum_a <= sum_b) {
ans = max((ll)ans,sum_a - (ll)W * (i + tmp));
}
}
return ans;
}
inline bool cmp(int a,int b) {
return a > b;
}
int n,W;
signed main () {
cin >> n >> W;
for(int i = 1;i <= n; ++i) {
cin >> a[i];
}
for(int i = 1;i <= n; ++i) {
cin >> b[i];
}
sort(a + 1,a + n + 1,cmp);sort(b + 1,b + n + 1,cmp);
int ans1 = solve(a,b,n,W);
int ans2 = solve(b,a,n,W);
printf("%lld\n",max(ans1,ans2));
return 0;
}
[NOI.AC] candy的更多相关文章
- NOI.AC NOIP模拟赛 第一场 补记
NOI.AC NOIP模拟赛 第一场 补记 candy 题目大意: 有两个超市,每个超市有\(n(n\le10^5)\)个糖,每个糖\(W\)元.每颗糖有一个愉悦度,其中,第一家商店中的第\(i\)颗 ...
- # NOI.AC省选赛 第五场T1 子集,与&最大值
NOI.AC省选赛 第五场T1 A. Mas的童年 题目链接 http://noi.ac/problem/309 思路 0x00 \(n^2\)的暴力挺简单的. ans=max(ans,xor[j-1 ...
- NOI.ac #31 MST DP、哈希
题目传送门:http://noi.ac/problem/31 一道思路好题考虑模拟$Kruskal$的加边方式,然后能够发现非最小生成树边只能在一个已经由边权更小的边连成的连通块中,而树边一定会让两个 ...
- NOI.AC NOIP模拟赛 第五场 游记
NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...
- NOI.AC NOIP模拟赛 第六场 游记
NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...
- NOI.AC NOIP模拟赛 第二场 补记
NOI.AC NOIP模拟赛 第二场 补记 palindrome 题目大意: 同[CEOI2017]Palindromic Partitions string 同[TC11326]Impossible ...
- NOI.AC NOIP模拟赛 第四场 补记
NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ...
- NOI.AC NOIP模拟赛 第三场 补记
NOI.AC NOIP模拟赛 第三场 补记 列队 题目大意: 给定一个\(n\times m(n,m\le1000)\)的矩阵,每个格子上有一个数\(w_{i,j}\).保证\(w_{i,j}\)互不 ...
- NOI.AC WC模拟赛
4C(容斥) http://noi.ac/contest/56/problem/25 同时交换一行或一列对答案显然没有影响,于是将行列均从大到小排序,每次处理限制相同的一段行列(呈一个L形). 问题变 ...
随机推荐
- 【leetcode】955. Delete Columns to Make Sorted II
题目如下: We are given an array A of N lowercase letter strings, all of the same length. Now, we may cho ...
- php随机生成数字加字母的字符串
function getRandomString($len, $chars=null) { if (is_null($chars)) { $chars = "ABCDEFGHIJKLMNOP ...
- C#接口的作用实例解析
一.接口的作用: 我们定义一个接口: public interface IBark { void Bark(); } 1. 再定义一个类,继承于IBark,并且必需实现其中的Bark()方法 pub ...
- SQL 与,或,非
SQL AND, OR and NOT(与,或不是运算符) AND&OR运算符用于根据一个以上的条件过滤记录. SQL AND & OR 运算符 WHERE子句可以与AND,OR和NO ...
- mockjs 使用以及反向校验
一.背景 前端开发需要依赖后端接口 后端接口输出慢.接口规范随时可能会变,而前端毫无感知 前端需要自己 mock 假数据 json 文件 假数据 json 数据内容是静态的,测试不同返回情况需要修改 ...
- 最常用的C++序列化方案:protobuf
参考链接:最常用的两种C++序列化方案的使用心得(protobuf和boost serialization) [c++] Google Protobuf库1. 什么是序列化?程序员在编写应用程序的时候 ...
- Ubuntu 没有 无线网 RTL8821ce 8111 8186
1.将ubuntu的linux内核版本更改到4.14(其他版本不兼容这个无线网卡的驱动) 1.1 找到内核版本 #到 Ubuntu网站http://kernel.ubuntu.com/~kernel- ...
- 2.2 webpack
webpack 介绍 webpack 是什么 为什么引入新的打包工具 webpack 核心思想 webpack 安装 webpack 使用 命令行调用 配置文件 webpack 配置参数 entry ...
- 关于版本管理工具SVN
曾经使用过Git,但是目前使用的是相对简单的svn. 刚使用的时候,如果不出意外.会有同学配好环境与权限. 前端只需要将代码下载,修改,更新,与上传. 一 .下载 1.本地新建文件夹,作为本地仓库 命 ...
- 要素选择变化事件 IActiveViewEvents_SelectionChanged
void IDockableWindowDef.OnCreate(object hook) { m_application = hook as IApplication; m_hookHelper = ...