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){;}

最新文章

  1. headroom.js –在不需要页头时将其隐藏
  2. Nginx配置location总结及rewrite规则写法
  3. PHPstorm设置连接FTP,进行文件上传、下载、比较
  4. Caffe学习系列(8):solver及其配置
  5. java删除被占用的文件
  6. OA
  7. 神州通,我看行---K2用户交流会华南站
  8. Android 混合开发 的一些心得。
  9. 1172 Hankson 的趣味题[数论]
  10. .net程序在无.net环境下运行
  11. ioc初步理解(二) 简单实用autofac搭建mvc三层+automapper=》ioc(codeFirst)
  12. java网络编程基本知识
  13. [模板] 树状数组 (C++ class)
  14. protobuf GetExtension
  15. ububuntu配置ip和dns
  16. springboot学习入门之二---配置文件解析
  17. oracle最大连接数相关
  18. [svc][op]Ubuntu初始化安装-py用机器优化
  19. Nginx反向代理 实现Web负载均衡
  20. Java多线程-线程的生命周期

热门文章

  1. linux中怎样关闭ICMP回应功能
  2. python爬虫基础11-selenium大全5/8-动作链
  3. leetcode-23-DynamicProgramming-1
  4. SolrCloud下DIH实践
  5. hdu-2544 最短路(最短路)
  6. poj-3278 catch that cow(搜索题)
  7. [每日App一]QQ主题要逆天!轻轻松松月入30万!
  8. concurrent.futures模块(进程池&amp;线程池)
  9. PHP中define()和const定义常量的区别
  10. 九度oj 题目1443:Tr A