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 1964. Chinese Dialects

WA#13 please help me in JAVA 1.7
Posted by Axmadjon 6 Jun 2014 12:28
import java.util.*;

public class Test_1874 {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner s = new Scanner(System.in);
        int n, k, m;

        n = s.nextInt();
        k = s.nextInt();

        long[] a = new long[k];
        for (int i = 0; i < k; i++) {
            a[i] = s.nextInt();
        }
        for (int i = 1; i < k; i++) {
            if (a[i] < a[i - 1]) {
                m = (int) a[i];
                a[i] = a[i - 1];
                a[i - 1] = m;
            }
        }
        m = (int) (n - (n - a[0]) - (n - a[1]));
        if (m <= 0) {
            System.out.println("0");
        } else {
            System.out.println(m);
        }
    }
}