ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1579. Coat Transportation

WA15
Posted by [RSU_Tash]Shavkat_Khusanov 10 Dec 2010 20:57
Why WA 15? Help me please.

import java.util.Arrays;
import java.util.Scanner;


public class Timus1579 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n=in.nextInt(),r=in.nextInt();
        Shub[] a=new Shub[n];
        Xod[] x=new Xod[n];
        int ix=1,im=0,gt=0;
        a[0]=new Shub(in.nextInt(),0);
        x[0]=new Xod(a[0].size);
        for(int i=1; i<n; i++){
            a[i]=new Shub(in.nextInt(),i);
            if(x[im].size+r<a[i].size){
                x[im].size=a[i].size;
                x[im].amount++;
                a[i].num=im;
                im=(im+1)%ix;
            }else{
                a[i].num=ix;
                x[ix]=new Xod(a[i].size);
                ix++;
            }
        }
        System.out.println(ix);
        Arrays.sort(a);

        for(int i=0; i<ix; i++){
            System.out.print(x[i].amount+" ");
            while((gt<n)&& (a[gt].num==i)){
                System.out.print((a[gt].num2+1)+" ");
                gt++;
            }
            System.out.println();
        }
    }
}
class Shub implements Comparable{
    int num,num2,size;

    public Shub(int s, int n) {
        num=0;
        size=s;
        num2=n;
    }

    public int compareTo(Object o) {
        Shub a=(Shub)o;
        if(num==a.num){
            return num2-a.num2;
        }else return num-a.num;
    }
}
class Xod{
    int size,amount;
    public Xod(int i) {
        size=i;
        amount=1;
    }
}