/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 47ms 812.0 KiB
#3 Wrong Answer 73ms 832.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int N,K;
        cin>>N>>K;
        int A[N];
        vector<int>v(N);
        for (int i=0; i<N; i++)
        {
            cin>>A[i];
            v.push_back(A[i]);
        }
        int max=A[0];
        int index=0;
        for (int i=0; i<K; i++)
        {
            if (A[i]>=max)
            {
                max=A[i];
                index=i;
            }
        }
        int a;
        int flag=0;
        for (int j=K; j<N; j++)
        {
            if (A[j]<max)
            {
                a=A[j];
                flag=1;
            }
        }

        int sum=0;
        for (int l=0; l<K; l++)
        {
            if (l!=index)
            {
                sum=sum+A[l];
            }
        }
        if (flag==1)
        {
            cout<<sum+a<<endl;
        }
        else
        {
            cout<<sum+max<<endl;
        }

    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1149 Swap and Minimize
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 06:10:25
Judged At
2024-12-09 06:10:25
Judged By
Score
1
Total Time
73ms
Peak Memory
832.0 KiB