【题目链接】:http://codeforces.com/contest/779/problem/C

【题意】



有n个商品;

打折前买和打折后买的价格不一样;

且必须有至少k个商品在打折前买;

问你买走全部n个商品最少需要多少钱;

【题解】

/*
每件商品先选择打折前和打折后里面价格较低的;
然后把价格全部加起来(我好像神经病写了个排序);
然后看看你选了几个第一种商品;
少选了,就选一些在打折后买的商品加上差价在打折前买;
把差价升序排一下,选择大于等于0的加上差价就是答案了
if (a[i]<b[i])
{
c[i].x = a[i];
c[i].id = 1;
}
else
{
//a[i]>=b[i]
c[i].x = b[i];
c[i].id = 2;
}
sort(c+1,c+1+n);
int ans = 0,num[3];
rep1(i,1,n)
ans+=c[i].x,num[c[i].id]++;
if (num[1]<k)
{
rep1(i,1,n)
c[i].x = b[i].x-a[i].x;
sort(c);
rep1(i,1,n)
if (c[i].x>=0)
{
if (num[1]<k)
{
ans+=c[i].x;
num[1]++;
}
else
break;
}
}
*/

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 2e5+1000; struct abc
{
int x, id;
}; int a[N], b[N],n ,k, num[3];
abc c[N]; bool cmp1(abc a, abc b)
{
return a.x < b.x;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n), rei(k);
rep1(i, 1, n)
rei(a[i]);
rep1(i, 1, n)
rei(b[i]);
rep1(i,1,n)
if (a[i]<b[i])
{
c[i].x = a[i];
c[i].id = 1;
}
else
{
//a[i]>=b[i]
c[i].x = b[i];
c[i].id = 2;
}
sort(c + 1, c + 1 + n,cmp1);
int ans = 0;
rep1(i, 1, n)
ans += c[i].x, num[c[i].id]++;
if (num[1]<k)
{
rep1(i, 1, n)
c[i].x = a[i] - b[i];
sort(c+1,c+1+n,cmp1);
rep1(i, 1, n)
if (c[i].x >= 0)
{
if (num[1]<k)
{
ans += c[i].x;
num[1]++;
}
else
break;
}
}
printf("%d\n", ans);
return 0;
}

【codeforces 779C】Dishonest Sellers的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. IDEACould not autowire. No beans of 'xxxMapper' type found.

    作为一名刚开始使用idea的新手,最近在使用maven+springMVC框架时遇到了这样一个问题:Could not autowire. No beans of 'xxxMapper' type f ...

  2. Oracle 中的Interger类型

    引自 wolfAone, oracle有没有integer类型,这种类型的最大值是多少啊. Integer是Number类型的子类型: NUMBER Type You use the NUMBER d ...

  3. 折叠table中的tr

    code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  4. (转)利用openfiler实现iSCSI

    转自:http://czmmiao.iteye.com/blog/1735417 openfiler openfiler是一个基于浏览器的网络存储管理工具.来自于Linux系统.openfiler在一 ...

  5. 11.2 Android显示系统框架_android源码禁用hwc和GPU

    2. 修改tiny4412_Android源码禁用hwc和gpu(厂家不会提供hwc和gpu的源代码,没有源代码就没法分析了,因此在这里禁用该功能并用软件库实现)最终源码: git clone htt ...

  6. SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active(转)

    趁今天有时间整理了一下 启动命令为 //开发环境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //测试环境 jav ...

  7. 在scala中调用java代码

      详细代码请见https://github.com/lujinhong/scalademo 在scala中调用java代替非常非常简单,直接调用即可 (一)一个简单示例 1.创建一个java类 pa ...

  8. gvim 窗口最大化启动

    此文来源于vimer的程序世界 首先需要 gvimfullscreen.dll 文件  下载gvimfullscreen.dll 下载源码 之后只需要在vimrc中配置如下代码就可以按F11使Vim全 ...

  9. 8、hzk16的介绍以及简单的使用方法

    HZK16 字库是符合GB2312标准的16×16点阵字库,HZK16的GB2312-80支持的汉字有6763个,符号682个.其中一级汉字有3755个,按 声序排列,二级汉字有3008个,按偏旁部首 ...

  10. 【例题3-5 UVA - 1583】Digit Generator

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] for (int i = 1;i <= n;i++) { 算出i是哪一个的生成元. 假设是y. 则ans[y] = min(a ...