AT_abc467_f.Email Scheduling Optimization
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given length-N sequences of positive integers A=(A1,A2,…,AN) and B=(B1,B2,…,BN).
You are given Q queries.
Each query is of one of the following two types.
1 i x: Change Ai to x.2 i x: Change Bi to x.
After processing each query, solve the following problem.
Takahashi needs to send an email to each of N companies and receive a reply from each of them.
Writing the email to send to the j-th company takes Aj minutes, and the reply arrives Bj minutes after it is sent.
He starts writing emails at time 0.
He can write the N emails in any order he likes, but he cannot write two or more emails simultaneously.
Find the minimum possible time at which he finishes receiving all of the replies.
Assume that the time taken to send emails is negligible.
给你两个长度为 N 的正整数序列 A=(A1,A2,…,AN) 和 B=(B1,B2,…,BN)。
你将收到 Q 个查询。
每个查询属于以下两种类型之一:
1 i x:将 Ai 修改为 x。2 i x:将 Bi 修改为 x。
在处理完每个查询后,请解决如下问题:
高桥需要向 N 家公司分别发送一封电子邮件,并从每家公司各收到一封回信。
向第 j 家公司发送邮件需耗时 Aj 分钟,且该邮件发出后 Bj 分钟会收到回信。
他从时刻 0 开始撰写邮件。
他可以按任意顺序撰写这 N 封邮件,但不能同时撰写多封邮件。
求他收齐所有回信的最早可能时刻。
假设发送邮件本身所需时间可忽略不计。
输入格式
The input is given from Standard Input in the following format:
N Q
A1 A2 … AN
B1 B2 … BN
query1
query2
⋮
queryQ
For each query queryq, the type of the query (1 or 2), i, and x are given in this order, separated by spaces.
That is, each query is given in one of the following two formats:
1 i x
2 i x
输入从标准输入给出,格式如下:
N Q
A1 A2 … AN
B1 B2 … BN
query1
query2
⋮
queryQ
对于每个查询 queryq,按顺序给出查询类型(1 或 2)、i 和 x,以空格分隔。
即,每个查询以以下两种格式之一给出:
1 i x
2 i x
输出格式
Output the answers in a total of Q lines. The q-th line should contain the answer to the problem after processing the q-th query.
在总共 Q 行中输出答案。第 q 行应包含处理完第 q 个查询后的答案。
输入输出样例
输入#1
3 3 4 6 7 4 6 7 1 2 1 2 3 7 2 3 1
输出#1
16 16 13
说明/提示
Sample 1 Explanation:
After processing the first query, A=(4,1,7) and B=(4,6,7).
If Takahashi starts writing the email to send to company 3 at time 0, finishes writing it at time 7, and sends it to company 3, he receives the reply at time 14.
If he starts writing the email to send to company 2 at time 7, finishes writing it at time 8, and sends it to company 2, he receives the reply at time 14.
If he starts writing the email to send to company 1 at time 8, finishes writing it at time 12, and sends it to company 1, he receives the reply at time 16.
Constraints
- 1≤N≤105
- 1≤Q≤105
- 1≤Aj,Bj≤109
- In each query, 1≤i≤N.
- In each query, 1≤x≤109.
- All input values are integers.
样例 1 解释:
处理第一个查询后,A=(4,1,7),B=(4,6,7)。
若高桥在时刻 0 开始撰写发给公司 3 的邮件,于时刻 7 完成撰写并发出,则他在时刻 14 收到回复。
若他在时刻 7 开始撰写发给公司 2 的邮件,于时刻 8 完成撰写并发出,则他在时刻 14 收到回复。
若他在时刻 8 开始撰写发给公司 1 的邮件,于时刻 12 完成撰写并发出,则他在时刻 16 收到回复。
限制条件
- 1≤N≤105
- 1≤Q≤105
- 1≤Aj,Bj≤109
- 每个查询中,1≤i≤N。
- 每个查询中,1≤x≤109。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?