Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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

HackerEarth Scoring in Exam problem solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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