###### BOJ 385

Problem C. Vaccine
Description
On Christmas Eve, 2029, the unidentified "Apocalypse Virus" spreads and
plunges JA into a state of emergency in a chaos known as the "Lost
Christmas" incident. An international organization known as the GHQ
intervenes with martial law and restores order to JA at the cost of its
independence. GHQ takes the domination of JA by the monopolization of
the vaccines, which are the only known solution to prevent the spreading
of the fatal Apocalypse Virus.
However, where there is oppression, there is resistance. The armed NGO
“Undertakers” is such a resistance group that aims to liberate JA from the
GHQ. One of the members' task is to manufacture the Anti-Apocalypse-
Virus vaccines. Of course, the government GHQ won't give them the raw
material as the Undertakers is announced as a terroristic organization. So
they have to get the material on their own.
Just as the sources of the raw material they get are various, the material
should be purified. The process of purification for each portion of raw
material needs 2 steps IN THE FOLLOWING ORDER:
1. take a portion of raw material into machine A to heat it to
142.857℃.
2. take the portion of raw material into machine B to centrifugalize it .
And the problem comes: Undertakers has only one machine A and only
one machine B. The machine A is able to handle only one portion of
material at a time, so is the machine B. However, there are N portions of
raw material in all, and the time for heating them and for centrifugalizing
them differs. So how to make a proper plan to purify them to minimumize
the total time? You may assume that taking a portion into a machine or
taking a portion out from a machine cost no time.
Input
There are multiple cases, end by EOF.
For each case, the first line contains an integer N (1 <= N <= 1000), the
number of portions of raw material. Then N lines followed, each contains
two integers, time for heat the ith portion of material and for
centrifugalize it respectively.
Output
For each case, output one integer, the minimum total time for purifying
these portions of raw material.
Sample Input
2 3
5
4 3
5 8
5
9 2
4 10
6 8
3 5
Sample Output
11
33
Hint
Take the first example for explaining. The following process takes the
minimum time:
At the beginning, take the first portion of material into machine A.
At the 3rd minute, take out the first portion from machine A and take it
into machine B, and then take the second portion into machine A.
At the 7th minute, take out the second portion from machine A.
At the 8th minute, take out the first portion from machine B and take the
second portion into machine B.
At the 11th minute, take out the second portion from machine B

#include<stdio.h>
#include<stdlib.h>
struct raw{
int a,b;
}lis[1010];
int max(int a,int b){
return a>b?a:b;
}
int cmp(const void * a,const void *b){
struct raw *aa=(struct raw *)a;
struct raw *bb=(struct raw *)b;
if(aa->a+bb->b+max(aa->b,bb->a)>aa->b+bb->a+max(aa->a,bb->b))
return 1;
return 0;
}
int main(){
int i,j,n;
while(scanf("%d",&n)!=EOF){
for(i=1;i<=n;i++){
scanf("%d %d",&lis[i].a,&lis[i].b);
}
qsort(&lis[1],n,sizeof(lis[1]),cmp);
int s=0,t=0;       //这里s记录上一过程中A机器运行结束时间，t记录上一过程中B机器运行结束时间
for(i=1;i<=n;i++){
if(s+lis[i].a>t)
t=s+lis[i].a;
s+=lis[i].a;
t+=lis[i].b;
}
printf("%d\n",t);
}
}

#### boj488. 小妹妹个数-素数个数题（打表...）

2014-08-08 12:07:43

#### BOJ 4358 左手定则

2014-03-28 18:31:42

#### 5道最基本的并查集- -！

2014-01-15 17:16:47

#### 11月--1922--偶是水题

2011-12-06 19:40:21

#### 斯坦福大学秋季课程《深度学习理论》STATS 385开讲

2017-11-09 16:09:35

#### o.boj 1495 麻烦的名词复数

2011-12-25 09:27:05

#### BOJ题目1023. Ancient Keyboard 源代码

2012年10月08日 561B 下载

#### 无法定位序数385 于动态链接库 licurl.dll

2016-05-20 16:01:27

#### 北邮OJ 84. Single Number

2016-03-10 09:58:07

#### boj 0809复试模拟题答案

2010年04月22日 853KB 下载

BOJ 385