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 1759. Long-Livers

Is d2 redundant?
Posted by Vitalii Arbuzov 24 Mar 2011 13:44
Can't understand why we need date starting from which person was the oldest.
Also can't understand why this solution gets WA3.
Can anyone help?

import java.util.GregorianCalendar;
import java.util.Scanner;

public class P1759 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.valueOf(scanner.nextLine());
        GregorianCalendar birth = (GregorianCalendar) GregorianCalendar.getInstance();
        GregorianCalendar death = (GregorianCalendar) GregorianCalendar.getInstance();
        long max = 0;
        int result = 0;
        long longestLiveDeath = 0;
        for (int i = 0; i < n; i++) {
            String[] dates = scanner.nextLine().split("\\s");

            set(birth, dates[0]);
            set(death, dates[2]);
            long liveTime = death.getTimeInMillis() - birth.getTimeInMillis();
            if (liveTime > max || (liveTime == max && death.getTimeInMillis() < longestLiveDeath)) {
                max = liveTime;
                longestLiveDeath = death.getTimeInMillis();
                result = i;
            }
        }
        System.out.println(result + 1);
    }

    private static void set(GregorianCalendar date, String sDate) {
        String[] split = sDate.split("\\.");
        date.set(Integer.valueOf(split[2]), Integer.valueOf(split[1]), Integer.valueOf(split[0]));
    }
}

Edited by author 24.03.2011 13:45