Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.StringTokenizer;
- import java.util.HashMap;
- import java.util.ArrayList;
- //Отдельное присвоение для каждой переменной строчкой
- //Лучше все таки поссчитать
- class Lis
- {
- int index;
- long current;
- long rival;
- Lis next;
- Lis(long current, long rival, int index)
- {
- this.current=current;
- this.rival=rival;
- this.index=index;
- next=null;
- }
- }
- public class Task {
- BufferedReader in;
- PrintWriter out;
- StringTokenizer st;
- Lis insert(Lis now,long current,long rival, int index)
- {
- now.next=new Lis(current,rival,index);
- return now.next;
- }
- public static void main(String[] args) throws IOException {
- Task solver = new Task();
- solver.open();
- solver.solve();
- solver.close();
- }
- private void solve() throws IOException {
- int n=nextInt();
- Lis list=new Lis(nextLong(),nextLong(),1);
- Lis first=list;
- long currentMax=0, rivalMax=0;
- currentMax+=list.current;
- rivalMax+=list.rival;
- for(int i=1;i<n;i++)
- {
- list=insert(list,nextLong(),nextLong(),i+1);
- currentMax+=list.current;
- rivalMax+=list.rival;
- }
- if (currentMax>rivalMax)
- {
- out.print("0");
- return;
- }
- else if (currentMax==rivalMax)
- {
- out.print("-1");
- return;
- }
- int temp=0;
- for(int i=0;i<n-1;i++)
- {
- if ((list.current>list.rival && list.next.current<list.next.rival) || (list.current<list.rival && list.next.current>list.next.rival))
- {
- if (list.current+list.next.current>list.rival+list.next.rival)
- {
- list.current=list.current+list.next.current;
- list.rival=list.rival+list.next.rival;
- list.next=list.next.next;
- temp++;
- }
- }else
- if (list.current+list.next.current<list.rival+list.next.rival)
- {
- list.current=list.current+list.next.current;
- list.rival=list.rival+list.next.rival;
- list.next=list.next.next;
- temp++;
- }
- }
- out.println(temp);
- for(int i=0;i<temp;i++)
- {
- if (first.next.index-1!=first.index)
- {
- out.println(first.index+" "+(first.index+1));
- }
- }
- }
- private long nextLong() throws IOException {
- return Long.parseLong(nextToken());
- }
- private void close() throws IOException {
- in.close();
- out.close();
- }
- private void open() {
- out = new PrintWriter(System.out);
- }
- public int nextInt() throws IOException {
- return Integer.parseInt(nextToken());
- }
- private String nextToken() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- String str = in.readLine();
- if (str == null) return null;
- st = new StringTokenizer(str);
- }
- return st.nextToken();
- }
- private boolean hasMoreTokens() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- String str = in.readLine();
- if (str == null) return false;
- st = new StringTokenizer(str);
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement