Submission #385792

#TimeUsernameProblemLanguageResultExecution timeMemory
385792SansPapyrus683Global Warming (CEOI18_glo)Java
100 / 100
500 ms39312 KiB
import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class glo { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer initial = new StringTokenizer(read.readLine()); int tempNum = Integer.parseInt(initial.nextToken()); int maxCheating = Integer.parseInt(initial.nextToken()); int[] temps = Arrays.stream(read.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); int[] prefLongest = new int[tempNum]; ArrayList<Integer> minEndings = new ArrayList<>(); for (int i = 0; i < tempNum; i++) { int t = temps[i]; int pos = bisectLeft(minEndings, t); prefLongest[i] = pos + 1; if (pos == minEndings.size()) { minEndings.add(t); } else { minEndings.set(pos, t); } } int longest = 0; ArrayList<Integer> maxBegins = new ArrayList<>(); for (int i = tempNum - 1; i >= 0; i--) { int t = temps[i]; int pos = bisectLeft(maxBegins, -t); longest = Math.max(longest, prefLongest[i] + pos); int insertPos = bisectLeft(maxBegins, -t - maxCheating); if (insertPos == maxBegins.size()) { maxBegins.add(-t - maxCheating); } else { maxBegins.set(insertPos, -t - maxCheating); } } System.out.println(longest); } private static int bisectLeft(List<Integer> arr, int x) { int lo = 0; int hi = arr.size(); while (lo < hi) { int mid = (lo + hi) / 2; if (arr.get(mid) < x) { lo = mid + 1; } else { hi = mid; } } return lo; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...