I am getting compilation error in this code

#include
#include<bits/stdc++.h>
#include<ctype.h>
#include
#include
#include
#include
using namespace std;

void sortArr(long long int arr[],long long int n)
{
vector<pair<long long int,long long int> > vp;
for (long long int i = 0; i < n; ++i) {
vp.push_back(make_pair(arr[i], i));
}
sort(vp.begin(), vp.end(),greater());
for (long long int i = 0; i < vp.size(); i++) {
cout << vp[i].second+1 << " ";
}
}
int main()
{ ios_base::sync_with_stdio(false);cin.tie(NULL);
long long int n,arr[1000000];cin>>n;
for(long long int j=0; j<n; j++)
{cin>>arr[j];}
sortArr(arr, n);
return 0;
}

Please either format your code or link to your submission - the forum software has mangled it so we can’t see what it was like originally! :slight_smile:

Also - what Problem are you trying to solve?

1 Like

First mistake: you passed the wrong type into greater. Note that each element is of type pair<long long int, int> in vp.

Second mistake: 1000000 \times 4 bytes probably won’t fit into that stack.

Here's the code that compiles.
#include<iostream>
#include<bits/stdc++.h>
#include<ctype.h>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
using namespace std;

void sortArr(long long int arr[],long long int n) 
{ 
    vector<pair<long long int,long long int> > vp; 
    for (long long int i = 0; i < n; ++i) { 
        vp.push_back(make_pair(arr[i], i)); 
    } 
    sort(vp.begin(), vp.end(),greater<pair<long long int, int> >());
//										^ before --> long long int
    for (long long int i = 0; i < vp.size(); i++) { 
        cout <<  vp[i].second+1 << " "; 
    } 
} 
int main() 
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int n,arr[100000];cin>>n;
//						^ before --> 1000000
     for(long long int j=0; j<n; j++)
     {cin>>arr[j];}
     sortArr(arr, n); 
  return 0; 
}

Hope this helps. :slightly_smiling_face:

1 Like