From d99adeaa91a86191657ed7fb419a93f2b356a133 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Mon, 15 Aug 2016 21:11:06 +0800 Subject: [PATCH] Create 100819S_standard.java --- Codeforces/Gym/100819S_standard.java | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Codeforces/Gym/100819S_standard.java diff --git a/Codeforces/Gym/100819S_standard.java b/Codeforces/Gym/100819S_standard.java new file mode 100644 index 0000000..af85a36 --- /dev/null +++ b/Codeforces/Gym/100819S_standard.java @@ -0,0 +1,33 @@ +import java.util.*; +public class Surf { + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + State[] list = new State[n]; + for(int i = 0; i < n; i++) { + list[i] = new State(sc.nextInt(), sc.nextInt(), sc.nextInt()); + } + Arrays.sort(list); + int[] dp = new int[2000001]; + int index = 0; + for(int i = 0; i < dp.length-1; i++) { + while(index < n && list[index].m == i) { + dp[i+list[index].w] = Math.max(dp[i+list[index].w], dp[i] + list[index].f); + index++; + } + dp[i+1] = Math.max(dp[i+1], dp[i]); + } + System.out.println(dp[2000000]); + } + static class State implements Comparable { + public int m,f,w; + public State(int a, int b, int c){ + m=a; + f=b; + w=c; + } + public int compareTo(State s) { + return m - s.m; + } + } +}