Codevs 1158 Nick's mission

Source: Internet
Author: User

"Title Description Description"

Nick connects to the Internet every day before he goes to work, receiving emails from his superiors, which contain all the tasks that the Nick's competent department has to accomplish on the day, each of which consists of a starting time and a duration.
One business day for Nick is n minutes, starting from the first minute to the nth minute. When Nick arrived at the unit, he began to work. If more than one task needs to be done at the same time, Nick can choose one of them to do, while the rest is done by his colleagues, and if there is only one task, then the task must be written by Nick, and if certain tasks start at the moment Nick is working, then these tasks are done by Nick's colleagues. If a task starts at p minutes and the duration is T minutes, the task ends at the first p+t-1 minute.
Write a program to calculate how Nick should pick a task to get the maximum spare time.

"Enter description input Description"
The first line of input data contains two integers separated by spaces N and K,1≤n≤10000,1≤k≤10000,n for Nick's working hours, in minutes, and K for the total number of tasks.
Then there are k lines, each line has two integers separated by a space of P and T, indicating that the task starts from P minutes and lasts for T minutes, where 1≤p≤n,1≤p+t-1≤n.

Outputs description Output Description
The output file contains only one line with an integer representing the maximum spare time that Nick may have.

"Sample input Sample"
15 6
1 2
1 6
4 11
8 5
8 1
11 5

"Sample output Sample Outputs"
4

"Problem-solving ideas"

It's actually quite obvious that this is a move-to-return

F[i] (indicates how much idle to the first minute) ={f[i-1]+1 (no tasks that start in the minute)

{max (F[i+t[j]] (maximum value of tasks starting from that minute)

1  Programnk;2 varF,a,b:Array[1..10001] ofLongint;3 Flag,max,t,n,i,j:longint;4 begin5 read (t,n);6      fori:=1  toN Doread (a[i],b[i]);7      fori:= TDownto 1  Do8     begin9flag:=0;Tenmax:=-1; One          forJ:=nDownto 1  Do A         begin -             if(a[j]=i) and(F[i+b[j]]>=max) Then -             begin themax:=f[i+B[j]]; -flag:=1; -             End; -             ifA[j]<i ThenBreak ; +         End; -         ifflag=1  ThenF[i]:=maxElsef[i]:=f[i+1]+1;//To judge whether there is a task +     End; AWriteln (f[1]); at End.

Codevs 1158 Nick's mission

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.