Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Easy Going (Very Easy) problem solution

YASH PAL, 31 July 2024
In this HackerEarth Easy Going(Very Easy) problem solution Coders here is a simple task for you, you have given an array of size N and an integer M.
Your task is to calculate the difference between the maximum sum and minimum sum of N-M elements of the given array.
HackerEarth Easy Going.(Very Easy) problem solution

HackerEarth Easy Going.(Very Easy) problem solution.

#include <iostream>

using namespace std;

void input (int arr[], int n) {

for (int i = 0; i < n; i++)

cin >> arr[i];

}
void sort (int a[], int s) {

for (int i = 0; i < s - 1; i++) {

for (int j = 0; j < s - i - 1; j++) {

if (a[j] > a[j + 1]) {

int temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

}

}

}

}




int main()

{

int n, m, t, arr[1000];

cin >> t;



for (int i = 0; i < t; i++) {

cin >> n >> m;

input (arr, n);

sort (arr, n);

int max = 0, min = 0, k = n - m;

for (int j = 0; j < k; j++){

max += arr[n - j - 1];

min += arr[j];

}

cout << max - min << endl;

}

return 0;

}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes