SPOILER
opt(i,L) is the number of combinations of length L t...
opt(i,L) is the number of combinations of length L t...
Do not add spaces at the end of each test case and add new line also for the last test case
Why don't we update (instead of adding) a pair in the priority queue, if it already exists ?
In the helper code provided by HackerRank, if you do not return a long long int, you will fail the test 11 : this is why you need to change not only the return type of the function : journeyToMoon , but also the variable that stores the result in the helper code into :
long long int result = journeyToMoon(n, astronaut);
#include <iostream>#include <algorithm>#include <vector>#include <queue>#define watch(x) cout << (#x) << " is " << (x) << endlusing namespace std;struct mypair{int a;int b;};bool mycmp(mypair p1, mypair p2){return (p1.a+p1.b)>(p2.a+p2.b);}int main() {ios::sync_with_stdio(false); // makes cin and cout as fast and scanf printf#ifndef ONLINE_JUDGE
#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <cmath>#define watch(x) cout << (#x) << " is " << (x) << endlusing namespace std;int main() {ios::sync_with_stdio(false); // makes cin and cout as fast and scanf printf#ifndef ONLINE_JUDGEfreopen("input.txt","r",stdin);freopen("output.txt","w",stdout);#endifint c;int test_n = 1;cin>>c;while(c--){int n,k,b,t;
I think the problem is the choice of the parameter : taking the greatest of tips is not the optimal choice. For example consider this case : A = [10,1 ], B = [11 ,8], X=1, Y=1 : the optimal choice is 8+11 = 19, while you algorithm : 11+1=12
This is my solution following the useful hint of Navkrishna Raghav
#include <iostream>#include <algorithm>#include <vector>#include <queue>#define watch(x) cout << (#x) << " is " << (x) << endlusing namespace std;struct job{long int a;long int b;long long int d;};bool cmp1(job j1, job j2){if (j1.d == j2.d)return j1.a<j2.a;return j1.d>j2.d ;}class cmp2{