CSES - Datatähti 2017 alku - Results
Submission details
Task:Kolikot
Sender:e^(pi*i)=-1
Submission time:2016-10-09 15:17:29 +0300
Language:Java
Status:READY
Result:57
Feedback
groupverdictscore
#1ACCEPTED22
#2ACCEPTED35
#30
Test results
testverdicttimegroup
#1ACCEPTED0.14 s1details
#2ACCEPTED0.12 s1details
#3ACCEPTED0.14 s1details
#4ACCEPTED0.14 s1details
#5ACCEPTED0.14 s1details
#6ACCEPTED0.14 s2details
#7ACCEPTED0.15 s2details
#8ACCEPTED0.15 s2details
#9ACCEPTED0.12 s2details
#10ACCEPTED0.15 s2details
#11ACCEPTED0.83 s3details
#12ACCEPTED0.31 s3details
#13ACCEPTED0.41 s3details
#14ACCEPTED0.43 s3details
#150.66 s3details
#16--3details

Code

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

public class Main
{
    static int[] coinValues;
    
    public static void main(String[] args)
    {
        Scanner inputTaker = new Scanner(System.in);
        
        int amountOfCoins = inputTaker.nextInt();
        inputTaker.nextLine();
        String coinsString = inputTaker.nextLine();
        
        int[] coins = new int[amountOfCoins];
        
        /*Now the input is handled into an array*/
        String[] coinsStringArray = coinsString.split(" ");
        for(int i = 0; i < amountOfCoins; i++)
        {
            coins[i] = Integer.parseInt(coinsStringArray[i]);
        }
        
        Arrays.sort(coins);
        coinValues = coins;
        
        /*Now begins the actual calculation for the first unpresentable number*/
        int lastValueOfCoins = 1;
        
        for(int i = 1; true; i++)
        {
            int coinFound = -1;
            /*coinFound is the coin that proves that i can be presented as a sum
            of some coins. If it remains as -1 after the second for-loop, no
            coin is found and the current i cannot be presented as a sum of
            coins.*/
            
            for(int j = lastValueOfCoins; j <= i; j++)
            {
                int index = Arrays.binarySearch(coins, j);
                if(index >= 0)
                {
                    int firstIndex = firstIndexOf(j, index);
                    coinFound = coins[firstIndex];
                    coins[firstIndex] = 0;
                    break;
                }
                else lastValueOfCoins = j;
            }
            
            if(coinFound != -1)
            {
                i += (coinFound - 1);
            }
            else
            {
                System.out.println(i);
                break;
            }
        }
    }
    
    public static int firstIndexOf(int numberSearched, int someIndex)
    {
        int firstIndex = someIndex;
        for(int i = someIndex - 1; true; i--)
        {
            try
            {
                if(coinValues[i] == numberSearched) firstIndex = i;
                else return firstIndex;
            }
            catch(Exception e)
            {
                return firstIndex;
            }
        }
    }
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
10
5 3 1 4 5 1 3 2 2 3

correct output
30

user output
30

Test 2

Group: 1

Verdict: ACCEPTED

input
10
3 5 5 4 5 4 5 5 5 3

correct output
1

user output
1

Test 3

Group: 1

Verdict: ACCEPTED

input
10
10 9 2 8 7 10 7 1 5 2

correct output
62

user output
62

Test 4

Group: 1

Verdict: ACCEPTED

input
10
7 4 6 3 9 7 4 4 7 7

correct output
1

user output
1

Test 5

Group: 1

Verdict: ACCEPTED

input
10
8 2 1 7 9 7 5 2 4 5

correct output
51

user output
51

Test 6

Group: 2

Verdict: ACCEPTED

input
100
3 3 1 4 2 1 2 1 3 1 2 5 1 5 1 ...

correct output
269

user output
269

Test 7

Group: 2

Verdict: ACCEPTED

input
100
3 3 2 3 4 5 4 4 4 4 2 2 4 4 4 ...

correct output
1

user output
1

Test 8

Group: 2

Verdict: ACCEPTED

input
100
678 999 374 759 437 390 832 54...

correct output
1

user output
1

Test 9

Group: 2

Verdict: ACCEPTED

input
100
862 537 633 807 666 248 237 5 ...

correct output
30

user output
30

Test 10

Group: 2

Verdict: ACCEPTED

input
100
874 302 384 920 76 28 762 163 ...

correct output
41765

user output
41765

Test 11

Group: 3

Verdict: ACCEPTED

input
100000
4 2 5 3 2 3 5 2 2 2 3 4 3 3 2 ...

correct output
299640

user output
299640

Test 12

Group: 3

Verdict: ACCEPTED

input
100000
2 5 5 5 5 2 4 4 3 2 3 2 5 5 3 ...

correct output
1

user output
1

Test 13

Group: 3

Verdict: ACCEPTED

input
100000
98146842 766872135 84108268 28...

correct output
1

user output
1

Test 14

Group: 3

Verdict: ACCEPTED

input
100000
932032495 1 849176169 78948957...

correct output
29970

user output
29970

Test 15

Group: 3

Verdict:

input
100000
35894853 796619259 699878597 4...

correct output
44965249639582

user output
-2142322900

Test 16

Group: 3

Verdict:

input
100000
930494676 960662779 904422858 ...

correct output
800020001

user output
(empty)