CSES - E4590 2018 5 - Results
Submission details
Task:Card game
Sender:david.meichel
Submission time:2018-10-13 13:57:30 +0300
Language:Java
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1UNKNOWN--details
#2UNKNOWN--details
#3UNKNOWN--details
#4UNKNOWN--details
#5UNKNOWN--details
#6UNKNOWN--details
#7UNKNOWN--details
#8UNKNOWN--details
#9UNKNOWN--details
#10UNKNOWN--details
#11UNKNOWN--details
#12UNKNOWN--details
#13UNKNOWN--details
#14UNKNOWN--details
#15UNKNOWN--details
#16UNKNOWN--details
#17UNKNOWN--details
#18UNKNOWN--details

Code

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;

public class TaskA
{
  public static  void main (String[] args)
  {
    TakeTime timer = new TakeTime(5);
    FastReader reader = new FastReader();
    int n = reader.nextInt();
    int[] input = new int[n];
    timer.store_time(0);
    for (int i = 0;i < n ;i++)
    {
      input[i] = reader.nextInt();
    } 
    //System.out.println("Time to read input: " + timer.get_time(0));
    timer.store_time(1);
    input = countingSort(input);
    //System.out.println("Time to sort input: " + timer.get_time(1));
    long sum = 0;
    timer.store_time(2);
    for (int i = n-1;i >= 2 ;i = i-3 )
    {
      sum += input[i-1] + input[i-2];    
    } 
    //System.out.println("Time to calculate sum: " + timer.get_time(2));
    System.out.println(sum);
  }
  public static int[] countingSort(int[] numbers)
  {
    int max = numbers[0];
    for (int i = 1; i < numbers.length; i++) {
      if (numbers[i] > max)
        max = numbers[i];
    }
    
    int[] sortedNumbers = new int[max+1];
    
    for (int i = 0; i < numbers.length; i++) {
      sortedNumbers[numbers[i]]++;
    }
    
    int insertPosition = 0;
    
    for (int i = 0; i <= max; i++) {
      for (int j = 0; j < sortedNumbers[i]; j++) {
        numbers[insertPosition] = i;
        insertPosition++;
      }
    }
    return numbers;
  }
}

class TakeTime
{
  static long[] times;
  public TakeTime(int a)
  {
    times = new long[a];
  }
  public void store_time(int a)
  {
    long start = System.nanoTime(); 
    times[a] = start;   
  }
   
  public double get_time(int a)
  {
    long elapsedTime = System.nanoTime() - times[a];;
    double seconds = (double)elapsedTime / 1000000000.0;
    return seconds;
  }
}
   
 
class FastReader
{ 
  BufferedReader br; 
  StringTokenizer st; 
  
  public FastReader() 
  { 
    br = new BufferedReader(new
    InputStreamReader(System.in)); 
  } 
  
  String next() 
  { 
    while (st == null || !st.hasMoreElements()) 
    { 
      try
      { 
        st = new StringTokenizer(br.readLine()); 
      } 
      catch (IOException  e) 
      { 
        e.printStackTrace(); 
      } 
    } 
    return st.nextToken(); 
  } 
  
  public int nextInt() 
  { 
    return Integer.parseInt(next()); 
  } 
  
  long nextLong() 
  { 
    return Long.parseLong(next()); 
  } 
  
  double nextDouble() 
  { 
    return Double.parseDouble(next()); 
  } 
  
  String nextLine() 
  { 
    String str = ""; 
    try
    { 
      str = br.readLine(); 
    } 
    catch (IOException e) 
    { 
      e.printStackTrace(); 
    } 
    return str; 
  } 
} 

Test details

Test 1

Verdict: UNKNOWN

input
6
2 1 5 3 4 3

correct output
10

user output
(not available)

Test 2

Verdict: UNKNOWN

input
5
1 2 5 4 3

correct output
7

user output
(not available)

Test 3

Verdict: UNKNOWN

input
27014
45 16 2 61 31 41 37 46 44 21 4...

correct output
582478

user output
(not available)

Test 4

Verdict: UNKNOWN

input
64473
11 6 3 7 9 4 1 11 13 11 2 10 6...

correct output
300696

user output
(not available)

Test 5

Verdict: UNKNOWN

input
64336
509145 587269 302927 583880 50...

correct output
21522871494

user output
(not available)

Test 6

Verdict: UNKNOWN

input
30336
557855 345472 141504 110157 11...

correct output
10130887318

user output
(not available)

Test 7

Verdict: UNKNOWN

input
4373
520104 402147 137925 983880 75...

correct output
1454728921

user output
(not available)

Test 8

Verdict: UNKNOWN

input
21999
144634 234821 827342 831785 88...

correct output
7319664049

user output
(not available)

Test 9

Verdict: UNKNOWN

input
100000
27571 375948 483033 881820 680...

correct output
33288800620

user output
(not available)

Test 10

Verdict: UNKNOWN

input
100000
57034 65824 99995 99996 74998 ...

correct output
3333333333

user output
(not available)

Test 11

Verdict: UNKNOWN

input
3
1 1 1

correct output
2

user output
(not available)

Test 12

Verdict: UNKNOWN

input
3
1 1 2

correct output
2

user output
(not available)

Test 13

Verdict: UNKNOWN

input
100000
1000000 1000000 1000000 100000...

correct output
66666000000

user output
(not available)

Test 14

Verdict: UNKNOWN

input
3
1 2 1

correct output
2

user output
(not available)

Test 15

Verdict: UNKNOWN

input
3
2 1 1

correct output
2

user output
(not available)

Test 16

Verdict: UNKNOWN

input
3
2 2 1

correct output
3

user output
(not available)

Test 17

Verdict: UNKNOWN

input
3
2 1 2

correct output
3

user output
(not available)

Test 18

Verdict: UNKNOWN

input
3
1 2 2

correct output
3

user output
(not available)