UVaLive 6698 Sightseeing Bus Drivers (水题,贪心)
题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少;
析:贪心策略,让大的和小的搭配,小的和大的搭配,是最优的。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 1e8;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, -1, 1, 1, -1};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn], b[maxn]; int main(){
int T; cin >> T;
while(T--){
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
for(int i = 0; i < n; ++i) scanf("%d", &b[i]);
sort(a, a+n); sort(b, b+n);
int ans = 0;
for(int i = 0, j = n-1; i < n; ++i, --j)
ans += Max(0, a[i]+b[j]-m);
printf("%d\n", ans);
}
return 0;
}
UVaLive 6698 Sightseeing Bus Drivers (水题,贪心)的更多相关文章
- Proving Equivalences UVALive - 4287(强连通分量 水题)
就是统计入度为0 的点 和 出度为0 的点 输出 大的那一个,, 若图中只有一个强连通分量 则输出0即可 和https://www.cnblogs.com/WTSRUVF/p/9301096.htm ...
- CodeForces 719B Anatoly and Cockroaches (水题贪心)
题意:给定一个序列,让你用最少的操作把它变成交替的,操作有两种,任意交换两种,再就是把一种变成另一种. 析:贪心,策略是分别从br开始和rb开始然后取最优,先交换,交换是最优的,不行再变色. 代码如下 ...
- Codeforces Round #303 (Div. 2) D. Queue 水题贪心
题目: 题意:给你n个数值,要求排列这个序列使得第k个数值的前K-1个数的和>=第k个数值的个数尽可能多: #include <iostream> #include <cstd ...
- UVALive 4192 Close Enough Computations 水题
Close Enough Computations 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge& ...
- UVALive 7275 Dice Cup (水题)
Dice Cup 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/D Description In many table-top ...
- 洛谷p1208 水题贪心 思想入门
题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是 ...
- CF 1008B Turn the Rectangles(水题+贪心)
There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it ...
- codeforces 637D D. Running with Obstacles(dp,水题,贪心)
题目链接: D. Running with Obstacles time limit per test 2 seconds memory limit per test 256 megabytes in ...
- codeforces 515C C. Drazil and Factorial(水题,贪心)
题目链接: C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- 想找个计算器当本命?来试试UWP应用《纸书科学计算器》
久违了.上次在博客园发文还是4年前,正是高中参加NOIP的时候.这4年里发生了很多事,乃至再次看到过去的文章时,仿佛看到了自己也不熟悉的风景.最近很想把我的博客重新拾起来,慢慢灌溉,写一些微不足道的技 ...
- HDU 1018 Big Number (阶乘位数)
题意: 给一个数n,返回该数的阶乘结果是一个多少位(十进制位)的整数. 思路: 用对数log来实现. 举个例子 一个三位数n 满足102 <= n < 103: 那么它的位数w 满足 w ...
- spm中头动绘图的理解,自带数据集
1.在得到头动评估的数据基础上,可以汇出头动变化的折线图. 运行本程序需要下载相应的实例数据 headmove_data.txt 头动是fMRI的一个重要问题,该程序画出了某个被试进行扫描时头动的具体 ...
- 手机GUI自动化测试介绍
手机GUI自动化测试介绍 Posted on 2013/05/15 Xing Binbin(测试工程师) 摘要 众所周知,自动化测试可以一定程度上减轻测试人员负担,提高测试效率,并且通过自动化还可以实 ...
- 2015年目标一:学习掌握python
俗话说:凡事预则立,不预则废.又到新的一年,给自己确定第一个目标:学习python.掌握python基本用法.其实2014年已经断断续续接触过python,但一直是不系统地在学习,而且基本上没有把py ...
- uploadify scriptData参数无法传参的问题
最近需要使用到uploadify,需要向后台传递参数,使用script最多只能够传递一个参数,当然也可以通过合并参数然后再在服务器段拆分参数的方法来传递多个参数,而uploadify插件提供的scri ...
- 顶 兼容各种浏览器js折叠菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- tilecache2.11在windows apache2.22安装部署
tilecache2.11在windows apache2.22安装部署 蔡建良 2013-09-03 一.安装环境 操作系统: Windows7 32位 Apache2.22 Python2.5 m ...
- android 深入研究ratingbar自定义
http://blog.csdn.net/rain_butterfly/article/details/22892879
- 企业网站DDOS防护解决方案
随着网络的普及,越来越多的企业开始了上网之路,由于网络安全知识的欠缺,很多企业以为做一个网站就 等于 网络化了,于是狠花血本请专业网络公司制作出各种漂亮的网页.但做完才发现,网络上的各种漏洞的DDOS ...