# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1083783 |
2024-09-04T06:38:59 Z |
bvd |
Art Exhibition (JOI18_art) |
Java 11 |
|
962 ms |
46968 KB |
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
public class art {
private static class Kattio extends PrintWriter {
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
private static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
private static final class Artwork {
public final long a;
public final int b;
public Artwork(long a, int b) {
this.a = a;
this.b = b;
}
}
private static int clamp(long x) {
if (x < 0) return -1;
if (x > 0) return 1;
return 0;
}
public static void main(String[] args) throws IOException {
Reader io = new Reader();
int n = io.nextInt();
Artwork[] artworks = new Artwork[n];
for (int i=0; i<n; ++i) {
artworks[i] = new Artwork(io.nextLong(), io.nextInt());
}
Arrays.sort(artworks, (t, o) -> clamp(t.a - o.a));
long[] f = new long[n+1];
f[0] = 0;
long minSoFar = (long) 4e18;
long result = 0;
long prev = 0;
for (int i=0; i<n; ++i) {
long cur = prev + artworks[i].b;
result = Math.max(result, artworks[i].b);
long tmp = cur - artworks[i].a;
result = Math.max(result, tmp - minSoFar);
minSoFar = Math.min(minSoFar, prev - artworks[i].a);
prev = cur;
}
System.out.println(result);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
9632 KB |
Output is correct |
2 |
Correct |
50 ms |
9120 KB |
Output is correct |
3 |
Correct |
58 ms |
9256 KB |
Output is correct |
4 |
Correct |
50 ms |
9000 KB |
Output is correct |
5 |
Correct |
51 ms |
9408 KB |
Output is correct |
6 |
Correct |
49 ms |
9548 KB |
Output is correct |
7 |
Correct |
49 ms |
9252 KB |
Output is correct |
8 |
Correct |
51 ms |
9188 KB |
Output is correct |
9 |
Correct |
51 ms |
9436 KB |
Output is correct |
10 |
Correct |
51 ms |
9616 KB |
Output is correct |
11 |
Correct |
50 ms |
9224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
9632 KB |
Output is correct |
2 |
Correct |
50 ms |
9120 KB |
Output is correct |
3 |
Correct |
58 ms |
9256 KB |
Output is correct |
4 |
Correct |
50 ms |
9000 KB |
Output is correct |
5 |
Correct |
51 ms |
9408 KB |
Output is correct |
6 |
Correct |
49 ms |
9548 KB |
Output is correct |
7 |
Correct |
49 ms |
9252 KB |
Output is correct |
8 |
Correct |
51 ms |
9188 KB |
Output is correct |
9 |
Correct |
51 ms |
9436 KB |
Output is correct |
10 |
Correct |
51 ms |
9616 KB |
Output is correct |
11 |
Correct |
50 ms |
9224 KB |
Output is correct |
12 |
Correct |
58 ms |
9500 KB |
Output is correct |
13 |
Correct |
56 ms |
9332 KB |
Output is correct |
14 |
Correct |
54 ms |
9492 KB |
Output is correct |
15 |
Correct |
57 ms |
9812 KB |
Output is correct |
16 |
Correct |
54 ms |
9584 KB |
Output is correct |
17 |
Correct |
54 ms |
9496 KB |
Output is correct |
18 |
Correct |
63 ms |
9836 KB |
Output is correct |
19 |
Correct |
54 ms |
9348 KB |
Output is correct |
20 |
Correct |
60 ms |
9072 KB |
Output is correct |
21 |
Correct |
53 ms |
9736 KB |
Output is correct |
22 |
Correct |
53 ms |
9692 KB |
Output is correct |
23 |
Correct |
55 ms |
9936 KB |
Output is correct |
24 |
Correct |
56 ms |
9260 KB |
Output is correct |
25 |
Correct |
54 ms |
9320 KB |
Output is correct |
26 |
Correct |
55 ms |
9224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
9632 KB |
Output is correct |
2 |
Correct |
50 ms |
9120 KB |
Output is correct |
3 |
Correct |
58 ms |
9256 KB |
Output is correct |
4 |
Correct |
50 ms |
9000 KB |
Output is correct |
5 |
Correct |
51 ms |
9408 KB |
Output is correct |
6 |
Correct |
49 ms |
9548 KB |
Output is correct |
7 |
Correct |
49 ms |
9252 KB |
Output is correct |
8 |
Correct |
51 ms |
9188 KB |
Output is correct |
9 |
Correct |
51 ms |
9436 KB |
Output is correct |
10 |
Correct |
51 ms |
9616 KB |
Output is correct |
11 |
Correct |
50 ms |
9224 KB |
Output is correct |
12 |
Correct |
58 ms |
9500 KB |
Output is correct |
13 |
Correct |
56 ms |
9332 KB |
Output is correct |
14 |
Correct |
54 ms |
9492 KB |
Output is correct |
15 |
Correct |
57 ms |
9812 KB |
Output is correct |
16 |
Correct |
54 ms |
9584 KB |
Output is correct |
17 |
Correct |
54 ms |
9496 KB |
Output is correct |
18 |
Correct |
63 ms |
9836 KB |
Output is correct |
19 |
Correct |
54 ms |
9348 KB |
Output is correct |
20 |
Correct |
60 ms |
9072 KB |
Output is correct |
21 |
Correct |
53 ms |
9736 KB |
Output is correct |
22 |
Correct |
53 ms |
9692 KB |
Output is correct |
23 |
Correct |
55 ms |
9936 KB |
Output is correct |
24 |
Correct |
56 ms |
9260 KB |
Output is correct |
25 |
Correct |
54 ms |
9320 KB |
Output is correct |
26 |
Correct |
55 ms |
9224 KB |
Output is correct |
27 |
Correct |
235 ms |
13280 KB |
Output is correct |
28 |
Correct |
249 ms |
13332 KB |
Output is correct |
29 |
Correct |
282 ms |
13384 KB |
Output is correct |
30 |
Correct |
254 ms |
12620 KB |
Output is correct |
31 |
Correct |
176 ms |
12532 KB |
Output is correct |
32 |
Correct |
228 ms |
13268 KB |
Output is correct |
33 |
Correct |
264 ms |
13316 KB |
Output is correct |
34 |
Correct |
255 ms |
13220 KB |
Output is correct |
35 |
Correct |
259 ms |
13540 KB |
Output is correct |
36 |
Correct |
189 ms |
13488 KB |
Output is correct |
37 |
Correct |
230 ms |
13508 KB |
Output is correct |
38 |
Correct |
231 ms |
12860 KB |
Output is correct |
39 |
Correct |
222 ms |
13524 KB |
Output is correct |
40 |
Correct |
204 ms |
13264 KB |
Output is correct |
41 |
Correct |
230 ms |
12992 KB |
Output is correct |
42 |
Correct |
245 ms |
13140 KB |
Output is correct |
43 |
Correct |
270 ms |
13708 KB |
Output is correct |
44 |
Correct |
286 ms |
13028 KB |
Output is correct |
45 |
Correct |
277 ms |
13460 KB |
Output is correct |
46 |
Correct |
250 ms |
13308 KB |
Output is correct |
47 |
Correct |
252 ms |
12976 KB |
Output is correct |
48 |
Correct |
274 ms |
12956 KB |
Output is correct |
49 |
Correct |
173 ms |
13020 KB |
Output is correct |
50 |
Correct |
260 ms |
13664 KB |
Output is correct |
51 |
Correct |
245 ms |
13184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
9632 KB |
Output is correct |
2 |
Correct |
50 ms |
9120 KB |
Output is correct |
3 |
Correct |
58 ms |
9256 KB |
Output is correct |
4 |
Correct |
50 ms |
9000 KB |
Output is correct |
5 |
Correct |
51 ms |
9408 KB |
Output is correct |
6 |
Correct |
49 ms |
9548 KB |
Output is correct |
7 |
Correct |
49 ms |
9252 KB |
Output is correct |
8 |
Correct |
51 ms |
9188 KB |
Output is correct |
9 |
Correct |
51 ms |
9436 KB |
Output is correct |
10 |
Correct |
51 ms |
9616 KB |
Output is correct |
11 |
Correct |
50 ms |
9224 KB |
Output is correct |
12 |
Correct |
58 ms |
9500 KB |
Output is correct |
13 |
Correct |
56 ms |
9332 KB |
Output is correct |
14 |
Correct |
54 ms |
9492 KB |
Output is correct |
15 |
Correct |
57 ms |
9812 KB |
Output is correct |
16 |
Correct |
54 ms |
9584 KB |
Output is correct |
17 |
Correct |
54 ms |
9496 KB |
Output is correct |
18 |
Correct |
63 ms |
9836 KB |
Output is correct |
19 |
Correct |
54 ms |
9348 KB |
Output is correct |
20 |
Correct |
60 ms |
9072 KB |
Output is correct |
21 |
Correct |
53 ms |
9736 KB |
Output is correct |
22 |
Correct |
53 ms |
9692 KB |
Output is correct |
23 |
Correct |
55 ms |
9936 KB |
Output is correct |
24 |
Correct |
56 ms |
9260 KB |
Output is correct |
25 |
Correct |
54 ms |
9320 KB |
Output is correct |
26 |
Correct |
55 ms |
9224 KB |
Output is correct |
27 |
Correct |
235 ms |
13280 KB |
Output is correct |
28 |
Correct |
249 ms |
13332 KB |
Output is correct |
29 |
Correct |
282 ms |
13384 KB |
Output is correct |
30 |
Correct |
254 ms |
12620 KB |
Output is correct |
31 |
Correct |
176 ms |
12532 KB |
Output is correct |
32 |
Correct |
228 ms |
13268 KB |
Output is correct |
33 |
Correct |
264 ms |
13316 KB |
Output is correct |
34 |
Correct |
255 ms |
13220 KB |
Output is correct |
35 |
Correct |
259 ms |
13540 KB |
Output is correct |
36 |
Correct |
189 ms |
13488 KB |
Output is correct |
37 |
Correct |
230 ms |
13508 KB |
Output is correct |
38 |
Correct |
231 ms |
12860 KB |
Output is correct |
39 |
Correct |
222 ms |
13524 KB |
Output is correct |
40 |
Correct |
204 ms |
13264 KB |
Output is correct |
41 |
Correct |
230 ms |
12992 KB |
Output is correct |
42 |
Correct |
245 ms |
13140 KB |
Output is correct |
43 |
Correct |
270 ms |
13708 KB |
Output is correct |
44 |
Correct |
286 ms |
13028 KB |
Output is correct |
45 |
Correct |
277 ms |
13460 KB |
Output is correct |
46 |
Correct |
250 ms |
13308 KB |
Output is correct |
47 |
Correct |
252 ms |
12976 KB |
Output is correct |
48 |
Correct |
274 ms |
12956 KB |
Output is correct |
49 |
Correct |
173 ms |
13020 KB |
Output is correct |
50 |
Correct |
260 ms |
13664 KB |
Output is correct |
51 |
Correct |
245 ms |
13184 KB |
Output is correct |
52 |
Correct |
859 ms |
40684 KB |
Output is correct |
53 |
Correct |
865 ms |
46828 KB |
Output is correct |
54 |
Correct |
935 ms |
46928 KB |
Output is correct |
55 |
Correct |
904 ms |
46132 KB |
Output is correct |
56 |
Correct |
792 ms |
46496 KB |
Output is correct |
57 |
Correct |
962 ms |
46328 KB |
Output is correct |
58 |
Correct |
831 ms |
46600 KB |
Output is correct |
59 |
Correct |
844 ms |
46560 KB |
Output is correct |
60 |
Correct |
831 ms |
46528 KB |
Output is correct |
61 |
Correct |
788 ms |
45916 KB |
Output is correct |
62 |
Correct |
874 ms |
46624 KB |
Output is correct |
63 |
Correct |
794 ms |
46968 KB |
Output is correct |
64 |
Correct |
884 ms |
46732 KB |
Output is correct |
65 |
Correct |
853 ms |
46756 KB |
Output is correct |
66 |
Correct |
877 ms |
46832 KB |
Output is correct |
67 |
Correct |
910 ms |
46656 KB |
Output is correct |
68 |
Correct |
883 ms |
46440 KB |
Output is correct |