Help needed in Go

Правка en1, от sankalp_, 2018-02-03 20:10:46

package main

import "fmt"

import "math"

func main(){

var n,k int;

fmt.Scanf("%d %d",&n,&k);

var arr[100] int;

for i := 0 ; i < n ; i++ {
    fmt.Scanf("%d",&arr[i]);
}

for i := 0 ; i < n ; i++ {
    max_idx,cur_max := i,arr[i] ;
    for j := i+1 ; j < n ; j++ {
        cur_max := int(math.Max(float64(cur_max),float64(arr[j])));
        if ( cur_max == arr[j] ){
            max_idx = j;
        }
    }
    arr[i],arr[max_idx] = arr[max_idx],arr[i];
}

cnt := 0;

for i := 0 ; i < n ; i++ {
    if (arr[i] >= arr[k-1] && arr[i] > 0){
        cnt++;
    } else{
        break;
    }
}

fmt.Println(cnt);

}

This was my code for 158A.

The output for the first test case on my PC was 6 but it shows 0 on cf server.

Can someone point out where I've gone wrong?

Thanks in advance :)

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский sankalp_ 2018-02-03 20:10:46 957 Initial revision (published)