当前位置:网站首页>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;
}边栏推荐
- The new media operation strategy (taking xiaohongshu as an example) helps you quickly master the creative method of popular models
- Qt的TQTreeWidget控件
- recyclerview计算滑动距离之computeHorizontalScrollExtent-computeHorizontalScrollRange-computeHorizontalScrol
- Vs2019 WinForm clr20r3 error
- 面试题 17.11. 单词距离 ●●
- [opencv] edge detection [API and source code implementation]
- PCL basic operation Encyclopedia
- 码蹄集 万民堂大厨
- Recommend short videos every week: more and more smart devices need collaboration, posing a greater challenge to the development of the Internet of things?
- 【论文笔记】基于在线预测和规划的机器人动态跟踪抓取方法
猜你喜欢

QVariant的使用

MathType安装和解决不能Crtl+V的问题

Notification设置的小图标显示的是小方块

Summary 1 - deep learning - basic knowledge learning

Extended configuration of static routing in the second experiment

The third programming competition of Wuhan University of technology b- save the kingdom of DAG (topological properties deal with accessibility Statistics)

Dom and events

The third experiment OSPF
![[training day15] boring [tree DP]](/img/78/dc80076bb9fc4cf008c51b00ece431.png)
[training day15] boring [tree DP]

MySQL data type
随机推荐
Severely crack down on illegal we media operators according to law: it is urgent to purify the we media industry
[natural language processing] [vector representation] augsbert: improve the data enhancement method of Bi encoders for paired sentence scoring tasks
Node.js operation database
Qt5.12 installation error prompt: c:\qt5.12.11\vcredist\vcredist_ msvc2019_ x86.exe /norestart /q
Two methods of printing strings in reverse order in C language
How painful is it to write unit tests?
access-list vs ip access-list
Madness. MySQL learning.
Qt的TQTreeWidget控件
Design of Butterworth filter and drawing of amplitude frequency characteristic curve
Deploy flash based websites using Google cloud
The new media operation strategy (taking xiaohongshu as an example) helps you quickly master the creative method of popular models
Qtreewidget control of QT
QT string operation
MatrixCube揭秘102——300行实现的完整分布式存储系统MatrixKV
QT log file system
技术美术百人计划学习笔记(2)--向量
Network Security Learning (16)
[paper notes] a meta reinforcement learning algorithm for causal discovery
依法严厉打击违规自媒体运营者:净化自媒体行业迫在眉睫