Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class AliceAndApples {
- static void solution() throws IOException {
- Apple[] a = new Apple[readInt()];
- long s = readInt();
- for (int i = 0; i < a.length; i++) {
- a[i] = new Apple(readInt(), readInt(), i + 1);
- }
- Arrays.sort(a);
- for (int i = 0; i < a.length; i++) {
- s -= a[i].a;
- if (s <= 0) {
- pw.print(-1);
- return;
- }
- s += a[i].b;
- }
- for (int i = 0; i < a.length; i++) {
- pw.print(a[i].num + " ");
- }
- }
- static class Apple implements Comparable<Apple> {
- int a, b, num;
- Apple(int a, int b, int num) {
- this.a = a;
- this.b = b;
- this.num = num;
- }
- int d() {
- return b - a;
- }
- @Override
- public int compareTo(Apple o) {
- int d1 = d(), d2 = o.d();
- if (d1 > 0 && d2 > 0) return a - o.a;
- if (d1 > 0) return -1;
- if (d2 > 0) return 1;
- return o.b - b;
- }
- }
- static String fileName = "apples";
- public static void main(String[] args) throws IOException {
- if (new File(fileName + ".in").exists()) {
- br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileName + ".in"))));
- pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(new File(fileName + ".out"))));
- } else {
- br = new BufferedReader(new InputStreamReader(System.in));
- pw = new PrintWriter(new BufferedOutputStream(System.out));
- }
- solution();
- pw.close();
- }
- static String readLine() throws IOException {
- while (st == null || !st.hasMoreTokens())
- st = new StringTokenizer(br.readLine());
- return st.nextToken("\n");
- }
- static boolean hasNext() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- String s = br.readLine();
- if (s == null) {
- return false;
- }
- st = new StringTokenizer(s);
- }
- return true;
- }
- static boolean hasNextInLine() {
- if (st == null || !st.hasMoreTokens()) {
- return false;
- }
- return true;
- }
- static void toNextLine() throws IOException {
- st = new StringTokenizer(br.readLine());
- }
- static String next() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- st = new StringTokenizer(br.readLine());
- }
- return st.nextToken();
- }
- static int readInt() throws IOException {
- return Integer.parseInt(next());
- }
- static long readLong() throws IOException {
- return Long.parseLong(next());
- }
- static short readShort() throws IOException {
- return Short.parseShort(next());
- }
- static byte readByte() throws IOException {
- return Byte.parseByte(next());
- }
- static double readDouble() throws IOException {
- return Double.parseDouble(next());
- }
- static PrintWriter pw;
- static BufferedReader br;
- static StringTokenizer st;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement