Submission #1180178

#TimeUsernameProblemLanguageResultExecution timeMemory
1180178vibhasJust Long Neckties (JOI20_ho_t1)Java
100 / 100
963 ms84408 KiB
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class ho_t1 { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // Read input long n = Long.parseLong(br.readLine()); // 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 StringTokenizer st = new StringTokenizer(br.readLine()); for (long i = 0; i <= n; i++) { long val = Long.parseLong(st.nextToken()); a.add(new Pair(val, i)); } // Read second part of the input st = new StringTokenizer(br.readLine()); for (long i = 0; i < n; i++) { b[(int) i] = Long.parseLong(st.nextToken()); } // 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...