Source Code
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,k;
	cin>>n;
	cin>>k;
	int t[n];
	for(int i=0;i<n;i++)cin>>t[i];
	
	sort(t,t+n);
	int max=t[0], i=1;
	k--;
	while(k-- && i<n){
		if(t[i]==t[i-1])max++;
		if(t[i]>t[i-1])max++;
		i++;
	}
	cout<<max<<endl;
	
	return 0;
}
Copy
Cutting Trees lianattily
GNU G++17
41 ms
500 KB
Wrong Answer