列表

详情


NC253174. Homework

描述

Colin has n optional courses numbered from 1 to n, so he has to do a lot of homework.

For the i-th course, Colin must write an essay with no less than a_i words. And Colin can write one word per second.

However, Colin wants to finish homework as fast as possible, so he decides to reuse his homework. For the i-th course homework, he can write a_i words directly, or spend c_i(c_i< a_i) seconds to copy and modify previous finished homework j(j\not=i). If a_j\ge a_i, he will just keep a_i words. But if a_j< a_i, he has to write another a_i-a_j words. Notice that Colin can finish his homework in any order.

Colin doesn't have enough time to make his homework plan because of the deadline, so he wants you to write a program to determine the order of doing homework so that he can finish homework as fast as possible(no matter write or copy).

输入描述

The first line contains one integer n \text{ } ( 1 \le n \le 10^5 ).

The second line contains n integers a_1,a_2, \cdots ,a_n \text{ } ( 2 \le a_i \le 10^5 ).

The third line contains n integers c_1,c_2,\cdots,c_n\text{ } (1 \le c_i< a_i).

输出描述

Print one integer representing the minimum number of seconds required to finish all homework.

示例1

输入:

5
800 1500 1000 2000 3000
50 40 60 80 100

输出:

3230

说明:

Finish the fifth homework first, and copy the fifth homework to others.
The number of seconds is 3000+50+40+60+80=3230.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++ 11.0.1) 解法, 执行用时: 75ms, 内存消耗: 2072K, 提交时间: 2023-06-08 00:24:05

 #include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 1000010
int n,ans,sum,a[N],b[N];
signed main(){
	cin>>n;
	for (int i=1;i<=n;i++)	cin>>a[i],ans=max(ans,a[i]);
	for (int i=1;i<=n;i++)	cin>>b[i],ans+=b[i],sum=max(sum,b[i]);
	cout<<ans-sum;
}

C++(g++ 7.5.0) 解法, 执行用时: 69ms, 内存消耗: 440K, 提交时间: 2023-06-22 01:29:36

#include<iostream>
using namespace std;
long n,cnt,ans,a;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		cnt=max(cnt,a);
    }
	for(int i=0;i<n;i++){
		cin>>a;
		cnt+=a;
		ans=max(ans,a);
	}
	cout<<cnt-ans;
	return 0;
}

Python3 解法, 执行用时: 155ms, 内存消耗: 20168K, 提交时间: 2023-06-03 19:51:15

n=int(input())
q=list(map(int,input().split()))
w=list(map(int,input().split()))
a=max(q)
for i in range(len(w)):
    a+=w[i]
print(a-max(w))

上一题