답안 #281995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281995 2020-08-23T18:40:55 Z FlashGamezzz Art Exhibition (JOI18_art) Java 11
50 / 100
1000 ms 135980 KB
import java.io.*;
import java.util.*;

public class art {
	static int n;
	static long[] max = new long[1100000], upd = new long[1100000];
	static void upd(int l, int u, long d) {
		upd(0, 0, n-1, l, u, d);
	}
	static void upd(int i, int s, int e, int l, int u, long d) {
		if (upd[i] != 0) { 
			max[i] += upd[i];
			if (s != e) { 
				upd[i * 2 + 1] += upd[i]; 
				upd[i * 2 + 2] += upd[i]; 
			}
			upd[i] = 0;
		} 
		if (s > e || s > u || e < l) {
			return; 
		}
		if (s >= l && e <= u) { 
			max[i] += d;
			if (s != e) { 
				upd[i * 2 + 1] += d; 
				upd[i * 2 + 2] += d; 
			} 
			return; 
		}  
		upd(i * 2 + 1, s, (s + e)/2, l, u, d); 
		upd(i * 2 + 2, (s + e)/2 + 1, e, l, u, d); 
		max[i] = Long.max(max[i * 2 + 1], max[i * 2 + 2]);
	}
	static long max(int l, int u) {
		return max(0, 0, n-1, l, u);
	}
	static long max(int i, int s, int e, int l, int u) {
		if (upd[i] != 0) { 
			max[i] += upd[i];
			if (s != e) { 
				upd[i * 2 + 1] += upd[i]; 
				upd[i * 2 + 2] += upd[i]; 
			}
			upd[i] = 0;
		}
		if (s > e || s > u || e < l) {
			return Long.MIN_VALUE; 
		}
		if (s >= l && e <= u) { 
			return max[i]; 
		}
		return Long.max(max(2*i+1, s, (s+e)/2, l, u), max(2*i+2, (s+e)/2+1, e, l, u)); 
	}
	static class paint implements Comparable<paint>{
		int a;
		long s;
		paint (int x, long y) {
			a = x;
			s = y;
		}
		public int compareTo(paint o) {
			if (s < o.s) {
				return -1;
			}
			if (s == o.s) {
				return 0;
			}
			return 1;
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		n = Integer.parseInt(br.readLine());
		PriorityQueue<paint> pq = new PriorityQueue<paint>();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			pq.add(new paint(Integer.parseInt(line[1]), Long.parseLong(line[0])));
		}
		long size = pq.peek().s;
		long ans = 0;
		upd(0, 0, pq.poll().a);
		for (int i = 1; i < n; i++) {
			paint c = pq.poll();
			upd(0, i-1, size-c.s);
			upd(0, i, c.a);
			ans = Long.max(ans, max(0, i));
			size = c.s;
		}
		pw.println(ans);
		pw.close();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 27644 KB Output is correct
2 Correct 94 ms 27624 KB Output is correct
3 Correct 92 ms 27572 KB Output is correct
4 Correct 93 ms 27508 KB Output is correct
5 Correct 93 ms 27416 KB Output is correct
6 Correct 94 ms 27496 KB Output is correct
7 Correct 95 ms 27644 KB Output is correct
8 Correct 111 ms 27520 KB Output is correct
9 Correct 106 ms 27548 KB Output is correct
10 Correct 94 ms 27512 KB Output is correct
11 Correct 101 ms 27548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 27644 KB Output is correct
2 Correct 94 ms 27624 KB Output is correct
3 Correct 92 ms 27572 KB Output is correct
4 Correct 93 ms 27508 KB Output is correct
5 Correct 93 ms 27416 KB Output is correct
6 Correct 94 ms 27496 KB Output is correct
7 Correct 95 ms 27644 KB Output is correct
8 Correct 111 ms 27520 KB Output is correct
9 Correct 106 ms 27548 KB Output is correct
10 Correct 94 ms 27512 KB Output is correct
11 Correct 101 ms 27548 KB Output is correct
12 Correct 111 ms 28264 KB Output is correct
13 Correct 119 ms 28104 KB Output is correct
14 Correct 122 ms 28664 KB Output is correct
15 Correct 110 ms 28520 KB Output is correct
16 Correct 114 ms 28168 KB Output is correct
17 Correct 118 ms 27872 KB Output is correct
18 Correct 112 ms 28544 KB Output is correct
19 Correct 114 ms 28676 KB Output is correct
20 Correct 118 ms 28540 KB Output is correct
21 Correct 114 ms 27960 KB Output is correct
22 Correct 111 ms 28276 KB Output is correct
23 Correct 118 ms 28216 KB Output is correct
24 Correct 114 ms 28388 KB Output is correct
25 Correct 122 ms 28444 KB Output is correct
26 Correct 121 ms 28592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 27644 KB Output is correct
2 Correct 94 ms 27624 KB Output is correct
3 Correct 92 ms 27572 KB Output is correct
4 Correct 93 ms 27508 KB Output is correct
5 Correct 93 ms 27416 KB Output is correct
6 Correct 94 ms 27496 KB Output is correct
7 Correct 95 ms 27644 KB Output is correct
8 Correct 111 ms 27520 KB Output is correct
9 Correct 106 ms 27548 KB Output is correct
10 Correct 94 ms 27512 KB Output is correct
11 Correct 101 ms 27548 KB Output is correct
12 Correct 111 ms 28264 KB Output is correct
13 Correct 119 ms 28104 KB Output is correct
14 Correct 122 ms 28664 KB Output is correct
15 Correct 110 ms 28520 KB Output is correct
16 Correct 114 ms 28168 KB Output is correct
17 Correct 118 ms 27872 KB Output is correct
18 Correct 112 ms 28544 KB Output is correct
19 Correct 114 ms 28676 KB Output is correct
20 Correct 118 ms 28540 KB Output is correct
21 Correct 114 ms 27960 KB Output is correct
22 Correct 111 ms 28276 KB Output is correct
23 Correct 118 ms 28216 KB Output is correct
24 Correct 114 ms 28388 KB Output is correct
25 Correct 122 ms 28444 KB Output is correct
26 Correct 121 ms 28592 KB Output is correct
27 Correct 271 ms 34708 KB Output is correct
28 Correct 259 ms 32608 KB Output is correct
29 Correct 279 ms 34996 KB Output is correct
30 Correct 234 ms 32980 KB Output is correct
31 Correct 239 ms 33264 KB Output is correct
32 Correct 273 ms 35068 KB Output is correct
33 Correct 236 ms 35052 KB Output is correct
34 Correct 272 ms 34152 KB Output is correct
35 Correct 245 ms 34872 KB Output is correct
36 Correct 263 ms 34964 KB Output is correct
37 Correct 257 ms 33880 KB Output is correct
38 Correct 269 ms 34940 KB Output is correct
39 Correct 292 ms 32804 KB Output is correct
40 Correct 257 ms 32624 KB Output is correct
41 Correct 253 ms 32668 KB Output is correct
42 Correct 268 ms 35008 KB Output is correct
43 Correct 270 ms 32608 KB Output is correct
44 Correct 260 ms 34852 KB Output is correct
45 Correct 284 ms 35240 KB Output is correct
46 Correct 261 ms 33044 KB Output is correct
47 Correct 249 ms 34824 KB Output is correct
48 Correct 266 ms 34140 KB Output is correct
49 Correct 268 ms 34988 KB Output is correct
50 Correct 249 ms 35164 KB Output is correct
51 Correct 258 ms 34896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 27644 KB Output is correct
2 Correct 94 ms 27624 KB Output is correct
3 Correct 92 ms 27572 KB Output is correct
4 Correct 93 ms 27508 KB Output is correct
5 Correct 93 ms 27416 KB Output is correct
6 Correct 94 ms 27496 KB Output is correct
7 Correct 95 ms 27644 KB Output is correct
8 Correct 111 ms 27520 KB Output is correct
9 Correct 106 ms 27548 KB Output is correct
10 Correct 94 ms 27512 KB Output is correct
11 Correct 101 ms 27548 KB Output is correct
12 Correct 111 ms 28264 KB Output is correct
13 Correct 119 ms 28104 KB Output is correct
14 Correct 122 ms 28664 KB Output is correct
15 Correct 110 ms 28520 KB Output is correct
16 Correct 114 ms 28168 KB Output is correct
17 Correct 118 ms 27872 KB Output is correct
18 Correct 112 ms 28544 KB Output is correct
19 Correct 114 ms 28676 KB Output is correct
20 Correct 118 ms 28540 KB Output is correct
21 Correct 114 ms 27960 KB Output is correct
22 Correct 111 ms 28276 KB Output is correct
23 Correct 118 ms 28216 KB Output is correct
24 Correct 114 ms 28388 KB Output is correct
25 Correct 122 ms 28444 KB Output is correct
26 Correct 121 ms 28592 KB Output is correct
27 Correct 271 ms 34708 KB Output is correct
28 Correct 259 ms 32608 KB Output is correct
29 Correct 279 ms 34996 KB Output is correct
30 Correct 234 ms 32980 KB Output is correct
31 Correct 239 ms 33264 KB Output is correct
32 Correct 273 ms 35068 KB Output is correct
33 Correct 236 ms 35052 KB Output is correct
34 Correct 272 ms 34152 KB Output is correct
35 Correct 245 ms 34872 KB Output is correct
36 Correct 263 ms 34964 KB Output is correct
37 Correct 257 ms 33880 KB Output is correct
38 Correct 269 ms 34940 KB Output is correct
39 Correct 292 ms 32804 KB Output is correct
40 Correct 257 ms 32624 KB Output is correct
41 Correct 253 ms 32668 KB Output is correct
42 Correct 268 ms 35008 KB Output is correct
43 Correct 270 ms 32608 KB Output is correct
44 Correct 260 ms 34852 KB Output is correct
45 Correct 284 ms 35240 KB Output is correct
46 Correct 261 ms 33044 KB Output is correct
47 Correct 249 ms 34824 KB Output is correct
48 Correct 266 ms 34140 KB Output is correct
49 Correct 268 ms 34988 KB Output is correct
50 Correct 249 ms 35164 KB Output is correct
51 Correct 258 ms 34896 KB Output is correct
52 Execution timed out 1129 ms 135980 KB Time limit exceeded
53 Halted 0 ms 0 KB -