fork download
  1. fun main() {
  2. val N=readLine()!!.toInt()
  3.  
  4. val list = readLine()!!.split(" ").map{it.toInt()}
  5. list.sorted()
  6.  
  7. var ans=list[0];
  8.  
  9. for(i in 1 until N){
  10. if(list[i]-1>list[i-1]){
  11. ans+=list[i]
  12. }
  13. }
  14.  
  15. println(ans)
  16.  
  17. }
Success #stdin #stdout 0.13s 41776KB
stdin
10
6 7 10 12 13 14 15 20 21 22
stdout
48