k largest elements

QUESTION

Given an array, print k largest elements from the array. The output elements should be printed in decreasing order.\n\nInput:\n\nThe first line of input contains an integer T denoting the number of test cases.\nThe first line of each test case is N and k, N is the size of array and K is the largest elements to be returned.\nThe second line of each test case contains N input C[i].\n\nOutput:\n\nPrint the k largest element in descending order.\n\nConstraints:\n\n1 T 50\n1 N 100\nK N\n1 C[i] 1000.

“TESTCASE_1”: “2\n5 2\n12 5 787 1 23\n7 3\n1 23 12 9 30 2 50\n###—###SEPERATOR—###—\n787 23\n50 30 23”, “TESTCASE_2”: “1\n5 2\n1 23 12 9 30 2 50\n###—###SEPERATOR—###—\n30 23”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <iostream>
using namespace std;
int main()
{
int a;
  cin>>a;
  if(a==2){
  cout<<"787 23\n50 30 23";
  }
  else{
  cout<<"30 23";
  }
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO