제출 #1180177

#제출 시각아이디문제언어결과실행 시간메모리
1180177vibhasJust Long Neckties (JOI20_ho_t1)Java
9 / 100
1101 ms181344 KiB
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class ho_t1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Read input long n = scanner.nextLong(); // Create arrays and lists ArrayList<Pair> a = new ArrayList<>(); long[] b = new long[(int) n]; long[] ans = new long[(int) n + 1]; // Read first part of the input for (long i = 0; i <= n; i++) { long val = scanner.nextLong(); a.add(new Pair(val, i)); } // Read second part of the input for (long i = 0; i < n; i++) { b[(int) i] = scanner.nextLong(); } // Sort the arrays Collections.sort(a, (p1, p2) -> Long.compare(p1.first, p2.first)); Arrays.sort(b); // Initialize the disgust variable long disgust = 0; // Calculate the disgust values for (long i = 0; i < n; i++) { disgust = Math.max(disgust, a.get((int) i).first - b[(int) i]); } // Assign disgust value to the ans array ans[(int) a.get((int) n).second] = disgust; // Update disgust values in reverse order for (long i = n - 1; i >= 0; i--) { disgust = Math.max(disgust, a.get((int) (i + 1)).first - b[(int) i]); ans[(int) a.get((int) i).second] = disgust; } // Output the result for (long i = 0; i <= n; i++) { System.out.print(ans[(int) i] + " "); } System.out.println(); } // Pair class to hold the value and its index static class Pair { long first; long second; Pair(long first, long second) { this.first = first; this.second = second; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...