Submission #4059659


Source Code Expand

Imports System.Collections.Generic
Imports System.Console
Module Program
    Sub Main()
        Dim InPutLine1() = Gets(0).Split(" "c)
        Dim InPutLine2() = Gets(0).Split(" "c)
        Dim IntN As Integer = CInt(InPutLine1(0))
        Dim IntK As Integer = CInt(InPutLine1(1))
        Dim IntArr() As Integer = GetInts(InPutLine2)
        Dim ans As Integer = 0
        Dim anstmp() As Integer
        Dim IntSum() As Integer
        Dim ii As Integer
        Dim i1 As Integer
        If IntN < IntK Or IntN < 1 Or IntN > 5000 Or IntK < 1 Or IntK > 5000 Then
            Exit Sub
        End If
        If IntArr.Min() < 0 Or IntArr.Max() > 1000 Then
            Exit Sub
        End If
        If IntN = IntK Then
            ans = IntArr.Max()
        ElseIf IntK = 1 Then
            ans = IntArr.Sum()
        ElseIf IntK = 2 Then
            ReDim anstmp(IntN - 2)
            For ii = 0 To IntN - 2
                ReDim IntSum(1)
                For i1 = 0 To ii
                    IntSum(0) += IntArr(i1)
                Next
                IntSum(1) = IntArr.Sum() - IntSum(0)
                If IntSum(0) > IntSum(1) Then
                    anstmp(ii) = IntSum(0)
                Else
                    anstmp(ii) = IntSum(1)
                End If
            Next
            ans = anstmp.Min()
        Else
            ans = 0
        End If
        Console.WriteLine(ans)
        Console.ReadLine()
    End Sub
    Function GetInts(Str As String()) As Integer()
        Dim s = Str, r(UBound(s)) As Integer
        For i As Integer = 0 To UBound(s) : r(i) = s(i) : Next i
        GetInts = r
    End Function
    Function Gets() As String()
        Gets = Console.ReadLine().Split(vbCrLf)
    End Function

End Module

Submission Info

Submission Time
Task A - One out of Three
User dvh
Language Visual Basic (Mono 4.0.1)
Score 0
Code Size 1796 Byte
Status CE