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 1193. Queue at the Exam

TO ADMINISTRATOR!WHAT IS #4 TEST?WHAT IS WRONG IN MY PROGRAM?PLEASE HELP ME
Posted by Kod 30 May 2010 15:44
import java.util.Scanner;

public class Queue {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        koor A[] = new koor[50];
        int i, j, st;
        int vaxt = 0;
        int temp, temp1, temp2;
        int max = 0;
        int N = input.nextInt();

        for (i = 1; i <= N; i++) {
            A[i] = new koor();
            A[i].T1 = input.nextInt();
            A[i].T2 = input.nextInt();
            A[i].T3 = input.nextInt();
        }


        for (i = 1; i <= N - 1; i++) {

            for (j = 1; j <= N - 1; j++) {

                if (A[j].T1 > A[j + 1].T1) {

                    temp = A[j].T1;
                    A[j].T1 = A[j + 1].T1;
                    A[j + 1].T1 = temp;

                    temp1 = A[j].T2;
                    A[j].T2 = A[j + 1].T2;
                    A[j + 1].T2 = temp1;

                    temp2 = A[j].T3;
                    A[j].T3 = A[j + 1].T3;
                    A[j + 1].T3 = temp2;

                }
            }
        }


        st = A[1].T1 + A[1].T2;

        if (st > A[1].T3) {
            vaxt = st - A[1].T3;
        }
        for (i = 2; i <= N; i++) {

            if (st > A[i].T1) {
                st += A[i].T2;
                if (st > A[i].T3) {
                    vaxt = st - A[i].T3;
                }
            } else {
                st = A[i].T1 + A[i].T2;
                if (st > A[i].T3) {
                    vaxt = st - A[i].T3;
                }
            }
            if (vaxt > max) {
                max = vaxt;
            }

        }
        System.out.println(max);
    }
}

class koor {

    int T1;
    int T2;
    int T3;
}

Edited by author 30.05.2010 15:45