Title 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 there is more than one task 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 done 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.
Input/output format
Input Format:
The first line of input data contains two integers separated by spaces N and K (1≤n≤10000,1≤k≤10000), n represents the working time of Nick, 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.
output Format:
The output file is only one line, containing an integer that represents the maximum spare time that Nick may have.
Input/Output sample
Input Sample # #:
15 61 21 64 118 58 111 5
Sample # # of output:
4
Just move the rules backwards.
1 /**/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 using namespacestd;8 Const intmxn=30000;9 intn,k;Ten intP[MXN],A[MXN]; One intF[MXN]; A intMain () { -scanf"%d%d",&n,&k); - inti,j; the for(i=1; i<=k;i++){ -scanf"%d%d",&p[i],&a[i]); - } - for(i=n;i;i--){ + intflag=0; - for(j=1; j<=k;j++){ + if(p[j]==i) { Aflag=1; atF[i]=max (f[i],f[i+A[j]]); - } - } - if(!flag) f[i]=f[i+1]+1; - } -printf"%d\n", f[1]); in return 0; -}
Rokua P1280 Nick's mission