https://daniu.luogu.org/problemnew/show/P1561

题目描述

Farmer John has discovered that his cows produce higher quality milk when they are subject to strenuous exercise. He therefore decides to send his N cows (1 <= N <= 25,000) to climb up and then back down a nearby mountain!

Cow i takes U(i) time to climb up the mountain and then D(i) time to climb down the mountain. Being domesticated cows, each cow needs the help of a farmer for each leg of the climb, but due to the poor economy, there are only two farmers available, Farmer John and his cousin Farmer Don. FJ plans to guide cows for the upward climb, and FD will then guide the cows for the downward climb. Since every cow needs a guide, and there is only one farmer for each part of the voyage, at most one cow may be climbing upward at any point in time (assisted by FJ), and at most one cow may be climbing down at any point in time (assisted by FD). A group of cows may temporarily accumulate at the top of the mountain if they climb up and then need to wait for FD's assistance before climbing down. Cows may climb down in a different order than they climbed up.

Please determine the least possible amount of time for all N cows to make the entire journey.

农场主约翰发现他的奶牛剧烈运动后产奶的质量更高,所以他决定让N头(1 <= N <= 25,000)奶牛去附近爬山再返回来。

第i头奶牛用时U(i)爬上山,用时D(i)下山。作为家畜,奶牛们每段路都要有农夫的帮助,可是由于经济疲软,农场里只有两个农夫John和Don。John计划引导奶牛爬山,Don引导奶牛下山。虽然每个奶牛都需要向导,但每段旅途只有一名农夫。所有任何时刻只有一头奶牛爬山也只能有一头奶牛下山,奶牛爬上山后,可以暂时停留在山顶上等待Don的帮助。奶牛上山的顺序和下山的顺序不一定要相同。

请计算出所有N 头牛完成旅程的最短时间。

输入输出格式

输入格式:

第一行,一个整数N

第2 到第N+1 行,每行两个用空格隔开的整数U(i)和D(i)。

(1 <= U(i), D(i) <= 50,000).

输出格式:

一行一个整数,表示所有N 头牛完成旅程的最短时间。

输入输出样例

输入样例#1: 复制

3
6 4
8 1
2 3
输出样例#1: 复制

17

 #include <cstdio>

 #define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b) inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
} int Presist()
{
int n,totu=,totd=;
int minu=1e9,mind=1e9; read(n);
for(int ui,di,i=; i<=n; ++i)
{
read(ui),read(di);
totu+=ui,minu=min(minu,ui);
totd+=di,mind=min(mind,di);
}
printf("%d\n",max(totu+mind,totd+minu));
return ;
} int Aptal=Presist();
int main(int arg,char**argv){;}

洛谷—— P1561 [USACO12JAN]爬山Mountain Climbing的更多相关文章

  1. 洛谷 P1561 [USACO12JAN]爬山Mountain Climbing

    传送门 题目大意: n头牛,上山时间为u(i),下山为d(i). 要求每一时刻最多只有一头牛上山,一头牛下山. 问每头牛都上下山后花费最少时间. 题解:贪心 推了推样例,发现上山时间一定,那找个下山最 ...

  2. P1561 [USACO12JAN]爬山Mountain Climbing

    P1561 [USACO12JAN]爬山Mountain Climbing 题目描述 Farmer John has discovered that his cows produce higher q ...

  3. 洛谷【P1561】[USACO12JAN]爬山Mountain Climbing

    我对\(Jhonson\)算法的理解:https://www.cnblogs.com/AKMer/p/9863620.html 题目传送门:https://www.luogu.org/problemn ...

  4. [USACO12JAN]爬山Mountain Climbing

    题目描述 Farmer John has discovered that his cows produce higher quality milk when they are subject to s ...

  5. 洛谷P3043 [USACO12JAN]牛联盟Bovine Alliance

    P3043 [USACO12JAN]牛联盟Bovine Alliance 题目描述 Bessie and her bovine pals from nearby farms have finally ...

  6. 洛谷 P1361 小猫爬山

    题目描述 WD和LHX饲养了N只小猫,这天,小猫们要去爬山.经历了千辛万苦,小猫们终于爬上了山顶,但是疲倦的它们再也不想徒步走下山了. WD和LHX只好花钱让它们坐索道下山.索道上的缆车最大承重量为W ...

  7. 洛谷——P1361 小猫爬山

    https://www.luogu.org/problem/show?pid=1361#sub 题目描述 WD和LHX饲养了N只小猫,这天,小猫们要去爬山.经历了千辛万苦,小猫们终于爬上了山顶,但是疲 ...

  8. 洛谷 P3040 [USACO12JAN]贝尔分享Bale Share

    P3040 [USACO12JAN]贝尔分享Bale Share 题目描述 Farmer John has just received a new shipment of N (1 <= N & ...

  9. 洛谷 P3041 [USACO12JAN] Video Game Combos

    题目描述 Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only v ...

随机推荐

  1. mybatis枚举类型处理器

    1. 定义枚举值的接口 public abstract interface ValuedEnum { int getValue(); } 所有要被mybatis处理的枚举类继承该接口 2. 定义枚举类 ...

  2. CUB reduce errorinvalid configuration argument

    解决CUB reduce errorinvalid configuration argument问题 在写TensorFlow代码时遇到报错 CUB reduce errorinvalid confi ...

  3. CodeForces 703A Mishka and trip

    Description Little Mishka is a great traveller and she visited many countries. After thinking about ...

  4. Django Form one

    前戏: FromData:三种方式获取FromData 1. 创建一个FromData 的对象,然后再用append 的方法追个添加键值对 var formdata = new FormData(); ...

  5. day01_06.比较运算符

    >  >=  =  <  <=  != == ===  !== 凡运算,必有运算结果,比较运算符的运算结果是布尔值 ==和===的区别 <?php $c = ( 3 == ...

  6. Response.End报错

    以下摘抄自博问:https://q.cnblogs.com/q/31506/       try catch中使用Response.End() 我在WebForm中用ajax发送请求到页面index. ...

  7. hadoop FileSystem类和SequenceFile类实例

    Hadoop的FileSystem类是与Hadoop的某一文件系统进行交互的API,虽然我们主要聚焦于HDFS实例,但还是应该集成FileSystem抽象类,并编写代码,使其在不同的文件系统中可移植, ...

  8. 用-webkit-box-reflect制作倒影

    1.只在webkit内核的浏览器上有效果 2.语法: -webkit-box-reflect: <direction> <offset> <mask-box-image& ...

  9. 【基础操作】2-sat

    $2-sat$ 是一个很不怎么考的内容($NOI2017$ 除外) 例题

  10. offsetWidth clientWidth scrollWidth 三者之间的区别和联系

    scrollWidth:对象的实际内容的宽度,不包边线宽度,会随对象中内容超过可视区后而变大. clientWidth:对象内容的可视区的宽度,不包滚动条等边线,会随对象显示大小的变化而改变. off ...