| 14967 | 2025-02-10 11:16:10 | markfsibian | Inverzió | cpp17 | Compilation error |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
vector<pair<int, int>> v;
int n, t;
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> t;
v.push_back({ t, i });
}
sort(v.begin(), v.end());
int maxi = 0, res = -1, ind = -1, kezd = -1;
for (int& e : v)
{
if (e.second > maxi)
maxi = e.second;
if (maxi - e.second > res)
{
res = maxi - e.second;
kezd = e.second;
ind = maxi;
}
}
if (res == -1)
{
cout << -1;
return 0;
}
cout << kezd << " " << ind;
}
open /var/local/lib/isolate/414/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:22:23: error: invalid initialization of reference of type 'int&' from expression of type 'std::pair<int, int>'
22 | for (int& e : v)
| ^
main.cpp:24:23: error: request for member 'second' in 'e', which is of non-class type 'int'
24 | if (e.second > maxi)
| ^~~~~~
main.cpp:25:34: error: request for member 'second' in 'e', which is of non-class type 'int'
25 | maxi = e.second;
| ^~~~~~
main.cpp:26:30: error: request for member 'second' in 'e', which is of non-class type 'int'
26 | if (maxi - e.second > res)
| ^~~~~~
main.cpp:28:40: error: request for member 'second' in 'e', which is of non-class type 'int'
28 | res = maxi - e.second;
| ^~~~~~
main.cpp:29:34: error: request for member 'second' in 'e', which is of non-class type 'int'
29 | kezd = e.second;
| ^~~~~~