【题目链接】: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. JavaScript---call()使用的一些疑问

    疑问:在使用.call()时,调用对象到底是否可以直接拥有了被调用者的方法和属性? 这里输出结果为:ReferenceError: o is not defined function Person(n ...

  2. CSS笔记 - fgm练习 2-8 - 简易日历

    <style> *{margin: 0; padding: 0} .outer{ width: 240px; margin: 10px auto; background: #f0f0f0; ...

  3. 快速创建SSH信任实现无密码登录

    1. 生成本机的公私钥匙对[oracle@Oracle11_2 scripts]$ -t rsa Generating public/private rsa key pair. Enter file ...

  4. Day2:列表、元组

    一.列表 1.定义与访问元素(按索引) #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan list_a = [&quo ...

  5. GO语言学习(五)Go 语言基础语法

    Go 标记 Go 程序可以由多个标记组成,可以是关键字,标识符,常量,字符串,符号.如以下 GO 语句由 6 个标记组成: fmt.Println("Hello, World!") ...

  6. 用static 创建类的单例

    1.0 说明 通过函数调用new的static 类对象,由于static 对象只能初始化一次,由此构成单例运行. 2.0  直接代码 代码为windows,win32工程,因为只有一个文件,不上传工程 ...

  7. 【Educational Codeforces Round 31 B】Japanese Crosswords Strike Back

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 所有数字的和加上n-1,如果为x则唯一,否则不唯一 [代码] #include <bits/stdc++.h> usin ...

  8. POJ 题目2823 Sliding Window(RMQ,固定区间长度)

    Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 46507   Accepted: 13442 ...

  9. Android实现主动连接蓝牙耳机

    在Android程序中可以实现自动扫描蓝牙.配对蓝牙.建立数据通道. 蓝牙分不同类型,可以参考(http://gqdy365.iteye.com/admin/blogs/2229304) 可以入下面方 ...

  10. mootools常用特性和示例(基础篇1)

    网上关于mootools这个库的信息很少. 公司一些老的项目用到了mootools库,因为要维护,所以接触到了mootools. mootools(文档)官网:http://www.chinamoot ...