MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Barrels/soultion.cpp:11–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9using namespace std;
10
11int main()
12{
13 int t; //define the variable that gonna hold the number of test cases
14 cin>>t; //take input
15 while(t--){
16 int n,k; //define n and k numbers that we gonna work with
17 long long int sum=0; //the maximum sum we gonna get *notation*:we define it as Long long because it will overflow int
18 cin>>n>>k; //take inputs
19 vector <int> v(n); //define vector of numbers of size n
20 for(int i=0;i<n;i++) cin>>v[i]; //taking input
21 sort(v.rbegin(),v.rend()); //sortthe vector in descending order
22 sum=v[0];
23 for(int i=1;i<=k;i++) sum+=v[i]; //calculating the maximum difference we could reach to
24 cout<<sum<<endl;
25 }
26 return 0;
27}
28//Happy Coding :))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected