Time Exceeded
Code
import java.util.Scanner;
import java.util.TreeMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
static Scanner in = new Scanner(System.in);
static int n, h, w, testCases, k;
static char x[];
static long a[];
static void solve() {
List<Long> list = new ArrayList<>();
for(int i = 0; i < n; ++i) {
list.add(a[i]);
}
Collections.sort(list);
List<Integer> index = new ArrayList<>();
int needReplace = 0, len = 0;
for(int i = 0, j = 0; i < n; ++i) {
if(list.get(i) != a[i]) {
++needReplace;
index.add(i + 1);
j = 1;
}
}
if(needReplace > k) {
System.out.println("NO");
} else {
System.out.println("YES");
System.out.println(index.get(0) + " " + index.get(index.size() - 1));
}
}
public static void main(String args[]) {
testCases = 1;
for(int t = 0; t < testCases; ++t) {
input();
solve();
}
}
private static void input() {
n = in.nextInt();
k = in.nextInt();
a = new long[n];
for(int i = 0; i < n; ++i) {
a[i] = in.nextLong();
}
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1120 Stairway to the Skyline
- Contest
- Brain Booster #7
- Language
- Java 8 (OpenJDK 1.8.0_422)
- Submit At
- 2024-11-05 15:57:24
- Judged At
- 2024-11-11 02:29:07
- Judged By
- Score
- 64
- Total Time
- ≥1012ms
- Peak Memory
- ≥85.262 MiB