sgu 259. Printed PR 贪心

本文介绍了一个小型公关机构接到大量宣传材料打印及配送任务的问题,并提供了一段C++代码来解决如何安排打印顺序以使所有材料从打印到送达的时间最短。

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

259. Printed PR
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
input: standard
output: standard



Small PR-agency got an order to print a very big lot of agitational materials. Agency should print and deliver N leaflets. Agency is very small and has only one printer, but it can print any leaflet. Leaflets can be different, so it is possible that times of printing of leaflets will differ. To print i-th leaflet the printer needs Ti minutes. When leaflet is printed, it should be immediately delivered to its addressee. The agency has unlimited number of couriers, so the courier gets the leaflet as soon as it printed and goes to the addressee. It takes Li minutes to deliver i-th leaflet. You were hired by agency to calculate the minimal time required to finish the job (this is an interval of time from the beginning of printing to the moment when the last leaflet is delivered), considering that the leaflets can be printed in any order.

Input
The first line contains a number of leaflets - integer number N (1 <= N <= 100). The second line contains N integer numbers Ti (1 <= i <= N). Third line contains N integer numbers Li (1 <= i <= N). You can assume that 1 <= Ti, Li <= 1000.

Output
You should output only one number - the answer for the problem.

Sample test(s)

Input
2 2 1 2 1
Output
4


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int a;
    int b;
}no[105];
bool cmp(node x,node y){
    return x.b>y.b;
}
int main()
{
    int N;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
        scanf("%d",&no[i].a);
    }
    for(int i=1;i<=N;i++)
    {
        scanf("%d",&no[i].b);
    }
    sort(no+1,no+1+N,cmp);
    int ans=0;
    int now=0;
    for(int i=1;i<=N;i++)
    {
        now+=no[i].a;
        ans=max(ans,now+no[i].b);
    }
    printf("%d",ans);
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值