제출 #1175621

#제출 시각아이디문제언어결과실행 시간메모리
1175621sp2028Art Exhibition (JOI18_art)Java
0 / 100
54 ms11328 KiB
import java.io.*;
import java.util.*;
public class art {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        long N = Long.parseLong(br.readLine());
        long[][] artworks = new long[(int) N][2];
        for (int i = 0; i < N; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            artworks[i][0] = Long.parseLong(st.nextToken()); 
            artworks[i][1] = Long.parseLong(st.nextToken());
        }
        Arrays.sort(artworks, Comparator.comparingLong(a -> a[0]));
        long max = Long.MIN_VALUE;
        int l = 0;
       long total = 0;
        for (int r = 0; r < N; r++) {
            total += artworks[r][1]; 
            while (l <= r && total < (artworks[r][0] - artworks[l][0])) {
                total -= artworks[l][1]; //update window
                l++;
            }
            max = Math.max(max, total - (artworks[r][0] - artworks[l][0]));//find the new max of the window
        }
        pw.println(max);
        pw.close();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...