Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Scoring in Exam problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Scoring in Exam problem solution Milly is at the examination hall where she is reading a question paper. She checked the question paper and discovered that there are N questions in that paper. Each question has some score value. Ideally it’s like questions requiring more time have more score value and strangely no two questions on the paper require same time to be solved.
 
She is very excited by looking these questions. She decided to solve K questions while maximizing their score value. Could you please help Milly to determine the exact time she needs to solve the questions.
 
 
HackerEarth Scoring in Exam problem solution

 

 

HackerEarth Scoring in Exam problem solution.

#include <bits/stdc++.h>

using namespace std;

long long t[100001];
long long scr[100001];
long long s[100001];

int main()
{
int n,q;
cin >> n >> q;
for(int i=0;i<n;i++) {
cin>>t[i];
}
for(int i=0;i<n;i++) {
cin>>scr[i];
}
sort(t,t+n);
s[n-1]=t[n-1];
for(int i=n-2;i>=0;i--) {
s[i]=t[i]+s[i+1];
}
for(int i=0;i<q;i++) {
int k;
cin>>k;
cout<<s[n-k]<<"n";
}
return 0;
}
 

Second solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define pi(a) printf("%d", a)
#define pl(a) printf("%lld", a)
#define pn printf("n")
ll pow_mod(ll a, ll b) {
ll res = 1;
while(b) {
if(b & 1)
res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
ll ar[1000005], ar1[1000005];
ll res[1000005];
bool compare(pair<ll, ll> p1, pair<ll, ll> p2) {
if(p1.first == p2.first) {
return p1.second < p2.second;
}
return p1.first < p2.first;
}
void test(int n) {
vector<pair<ll, ll> > v;
for(int i = 0; i < n; ++i) {
v.push_back(make_pair(ar[i], ar1[i]));
}
sort(v.begin(), v.end(), compare);
for(int i = 1; i < n; ++i) {
assert(v[i].first >= v[i - 1].first && v[i].second >= v[i - 1].second);
}
}
int main() {
int n, q;
si(n); si(q);
for(int i = 0; i < n; ++i) {
sl(ar[i]);
}
for(int i = 0; i < n; ++i) {
sl(ar1[i]);
}
test(n);
sort(ar, ar + n);
reverse(ar, ar + n);
res[0] = ar[0];
for(int i = 1; i < n; ++i) {
res[i] = res[i - 1] + ar[i];
}
int k;
while(q--) {
si(k);
pl(res[k - 1]);
pn;
}
return 0;
}
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

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