My code : https://pastebin.com/bMYpZ5PK
Please find the error (logical or typo).
I don’t think you know std::sort sorts in ascending order, not descending,
Oh yeah, just realised that. Sorry.
second for loop n to n+m, not n to m.
also the faster approach is this
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int seq1[n];
int seq2[m];
for(int i=0;i<n;i++){
cin>>seq1[i];
}
for(int i=0;i<m;i++){
cin>>seq2[i];
}
int idx1=0;
int idx2=0;
for(int i=0;i<n+m;i++){
if(idx1<n && idx2<m){
if(seq1[idx1]>seq2[idx2]){
cout<<seq1[idx1]<<" ";
idx1++;
}
else{
cout<<seq2[idx2]<<" ";
idx2++;
}
}
else if(idx1<n){
cout<<seq1[idx1]<<" ";
idx1++;
}
else{
cout<<seq2[idx2]<<" ";
idx2++;
}
}
cout<<"\n";
}
}
Works, thanks a lot !
Why don’t you try codechef questions.
Those 2-3 questions were very standard with little to learn
The problem is I’m a beginner, I really don’t know where to start from.
I’m following this flowchart : https://www.hackerearth.com/getstarted-competitive-programming/
I would surely like some guidance and suggestions from an expert.
I’m not an expert, Even i started 3 months ago. just very determined i guess.
I’ll give you 3 of favorite easy problems.
Try this. it’s really easy but it shows the usefulness of precomputation.