Wrong Answer
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