uva 11269 - Setting Problems(greedy)

本文介绍了一种算法,用于解决编程竞赛中问题集编排的时间优化问题。通过合理安排两个参与者的工作流程,确保能在最短时间内完成所有问题的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem J
Setting Problems

Input: Standard Input

Output: Standard Output

 

As you see, setting problems for a programming contest is a tough job. There are so many things to do like creating problems, solutions, data files, verification of problem statements, writing alternate judge solutions etc. etc. Given the responsibility of creating the problemset for ‘If you can not crash judges by solutions, crash contestants by problems’ programming contest, Sultan & GolapiBaba have realized that to the backbone. Finally they agree that they will set N problems for the contest. For each of the problems, first Sultan will create the problem statement, solution & i/o data. After he finishes his work, GolapiBaba does the verification & alternate solution writing part for that particular problem. Each of them needs a particular amount of time to complete their tasks for a certain problem. Also, none of them works on more than one problem at a time. Note that, GolapiBaba can start working on a problem immediately after Sultan finishes that problem or he may wish to start that problem later.

 

You will be given the times that Sultan & GolapiBaba requires to complete their respective tasks for every single problem. Determine the minimum possible time required to complete the whole problemset.

 

Input

 

There are around 50 test cases. Each test case starts with a single integer N (1<=N<=20), the number of problems in the contest. The next line contains N integers Si (1<=Si<=1001<=i<=N) where Si denotes the time required for Sultan to complete his tasks for problem i. The next line has N more integers Gi (1<=Gi<=1001<=i<=N) where Gi denotes the time required for Golapibaba to complete his tasks on problem i.

 

Output

 

For each test case, print the minimum time required to complete the problemset.

 

Sample Input

Sample Output

3

8 1 6

1 6 3

3

4 5 6

1 1 6

 

16

16

 




x1+x2+(y1-x2)+y2 == x1+x2+(y2-x1)+y1
(y1-x2)+y2 == (y2-x1)+y1

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 30;
struct task{
	int a , b;
}T[maxn];
int N;

bool cmp(task t1 , task t2){
	if(t1.b > t2.a && t2.b > t1.a) return t1.a<t2.a;
	if(t1.b > t2.a) return t2.b<t2.a;
	if(t2.b > t1.a) return t1.a<t1.b;
	return t2.b<t1.b;
}

void initial(){
	for(int i = 0; i < maxn; i++){
		T[i].a = 0;
		T[i].b = 0;
	}
}

void readcase(){
	int cost;
	for(int i = 0; i < N; i++){
		scanf("%d" , &cost);
		T[i].a = cost;
	}
	for(int i = 0; i < N; i++){
		scanf("%d" , &cost);
		T[i].b = cost;
	}
}

void computing(){
	sort(T , T+N , cmp);
	int ans = 0 , now = 0;
	for(int i = 0; i < N; i++){
		if(ans < now+T[i].a) ans = now+T[i].a+T[i].b;
		else ans += T[i].b;
		now += T[i].a;
	}
	printf("%d\n" , ans);
}

int main(){
	while(scanf("%d" , &N) != EOF){
		initial();
		readcase();
		computing();
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值