当前位置:网站首页>Zcmu--5015: complete the task
Zcmu--5015: complete the task
2022-07-25 22:59:00 【Little why】
Description
zbj Recently started playing a single game , This game is very interesting , There is no limit to the acceptance of all tasks , So he took all the tasks he could take at one time , But at this time, he found a very serious problem , In total, he accepted n A mission , Each task has the remaining completion time and the monetary reward of this task
Now for the convenience of ,zbj Suppose the current time is 0, He knows the remaining completion time and completion money of each task , And the time to complete a task is 1.
I hope you can tell him how to complete the task to get as much money as possible
Input
The first line contains an integer n, Expressing common ownership n A mission .
The second line contains n It's an integer ai, It means the first one i The remaining completion time of this task
The third line contains n It's an integer bi, It means the first one i Monetary reward for this task
(1<=ai,bi,n<=1000)
Output
The output contains an integer , It means the most money you can get .
Sample Input
3
1 3 1
6 2 3
Sample Output
8
analysis : Initially, it must be sorted from large to small according to the bonus , If the bonus is the same, the remaining time is small , Then open an array m To record the number of i Whether a time point is occupied , Then traverse a wave , If at present ti The time point is not occupied , Then occupy ti At this point in time , If occupied , We just keep moving forward to find a time point that is not occupied , Just take it , In this way, we can maximize the total amount .
#include <stdio.h>
#include <algorithm>
using namespace std;
struct s
{
int t,v;
bool operator<(const s&x)const{ // Prioritize according to bonus , Second in time
if(v!=x.v) return v>x.v;
return t<x.t;
}
}a[1005];
int m[1005]={0};// Record No. i Whether the time points are occupied ,0 Indicates not used ,1 Indicates that... Has been used
int main()
{
int n,i,s=0,p;
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&a[i].t);
for(i=0;i<n;i++) scanf("%d",&a[i].v);
sort(a,a+n);
for(i=0;i<n;i++){
p=a[i].t;
if(m[p]==0) m[p]=1,s+=a[i].v;// At present p The time point is not occupied , Occupied and marked 1
else{ // At present p Already occupied , Move forward
while(m[p]==1&&p>0) p--; // Until you find an unused node , sign out
if(p>0) m[p]=1,s+=a[i].v; // Because of time >0, Set a boundary
}
}
printf("%d\n",s);
return 0;
}边栏推荐
- Learning notes of technical art hundred people plan (1) -- basic rendering pipeline
- JS makes elements get or lose focus
- Basic knowledge of radar
- Common software shortcuts
- How painful is it to write unit tests?
- Why is Google's internal tools not suitable for you?
- [PTA] 7-19 check face value (15 points)
- MatrixCube揭秘102——300行实现的完整分布式存储系统MatrixKV
- Vs2019 WinForm clr20r3 error
- [natural language processing] [vector representation] augsbert: improve the data enhancement method of Bi encoders for paired sentence scoring tasks
猜你喜欢

DOM event binding

Basic knowledge of radar
![[文献阅读] - HRL -[HRL with Universal Policies for Multi-Step Robotic Manipulation]](/img/34/06d5ba3af4e6e775a335324c020161.png)
[文献阅读] - HRL -[HRL with Universal Policies for Multi-Step Robotic Manipulation]

The fourth experiment nat

Kibana~后台启动Kibana之后无法找到进程号

Two methods of printing strings in reverse order in C language
![[training day13] backpack [dynamic planning] [greed]](/img/a7/3df395d84f510dea8b42ebcc4ff5f2.png)
[training day13] backpack [dynamic planning] [greed]

Opencv compile and call GPU version

单模型常识推理首超人类!HFL登顶OpenBookQA挑战赛

Network Security Learning (XIV) IP protocol
随机推荐
MySQL data type
码蹄集 精准弹幕
Understanding of forward proxy and reverse proxy
Anaconda~Upload did not complete.
Experiment 1, experiment 2 and Experiment 3 of assembly language and microcomputer principle: branch program design / loop program design / subroutine design
The difference between abstract classes and interfaces
面试题 17.11. 单词距离 ●●
HCIE终到手,路才开始
[paper notes] robot dynamic tracking and grasping method based on online prediction and planning
Qtreewidget control of QT
单模型常识推理首超人类!HFL登顶OpenBookQA挑战赛
Tree view model example of QT
Panzer_ Jack's personal blog founding day
QT Chinese programming encounters c2001 error, prompting "there is a newline character in the constant"
汇编语言与微机原理实验一、实验二、实验三:分支程序设计/循环程序设计/子程序设计
Code shoe set precision barrage
How to obtain the cash flow data of advertising services to help analyze the advertising effect?
What are the differences between FileInputStream and bufferedinputstream?
Similarities and differences between equals and "= ="
Von Neumann architecture