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 1787. Turn for MEGA

WA Test #3
Posted by TwoFace 14 Jul 2015 10:25
import java.util.*;
import java.io.*;

public class MEGA
{
    public static void main(String arg[])
    {
        int k,n,i,sum=0;
        Scanner scan=new Scanner(System.in);
        k=scan.nextInt();
        n=scan.nextInt();
        int[] a=new int[n];
        for(i=0;i<n;)
        {
            if(scan.hasNextInt())
            {
                a[i]=scan.nextInt();
                i++;
            }
        }
        for(i=0;i<n;i++)
        {
            sum+=a[i]-k;
        }
        if(sum<0)
        {
            System.out.println("1");
        }
        else
        {
            System.out.println(""+sum);
        }
    }
}

This very simple program is turning out to be a headache. What is Test #3?
Re: WA Test #3
Posted by Vasiliy Kobozev 4 Dec 2016 16:17
inside cycle you need to check that (sum + a[i] - k) >=0

Edited by author 04.12.2016 16:18

Edited by author 04.12.2016 16:18