Cho a[n]. In ra hai vị trí sao cho tích của hai giá trị mà vị trí vừa in là bé nhất
#include <bits/stdc++.h>
#include <map>
#define hieuhfgr ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define gcd __gcd
#define pb push_back
#define fi first
#define se second
#define oo 1e9
#define endl "\n"
#define FILENAME "DATA"
#define file freopen(FILENAME".INP", "r", stdin);freopen(FILENAME".OUT", "w", stdout)
using namespace std;
const int maxn = 1e5;
int main(){
hieuhfgr;
int n;
int a[maxn];
cin >> n;
for (int i=1;i <= n;i++) cin >> a[i];
int maxpos[2] = {1, 1}; //{am, duong}
int minpos[2][2] = {
{-1, 1},
{-1, 1}
};
//min_pos[i][j]: i = 0: am, i = 1: duong, j: luu hai vi tri
for (int i=1;i <= n;i++) {
if (a[maxpos[0]] > a[i]) maxpos[0] = i;
if (a[maxpos[1]] < a[i]) maxpos[1] = i;
if (a[i] <= 0) {
if (a[minpos[0][1]] < a[i]) {
minpos[0][1] = i;
}
}
else {
if (a[minpos[1][1]] > a[i]) {
minpos[1][1] = i;
}
}
}
for (int i=1;i <= n;i++) {
if (a[i] <= 0) {
if (i == minpos[0][1]) continue;
if (minpos[0][0] == -1) minpos[0][0] = i;
else if (a[i] > a[minpos[0][0]]) minpos[0][0] = i;
}
else {
if (i == minpos[1][1]) continue;
if (minpos[1][0] == -1) minpos[1][0] = i;
else if (a[i] < a[minpos[1][0]]) minpos[1][0] = i;
}
}
// for(int i=0;i <= 1;i++) {
// for(int j=0;j <= 1;j++) cout << minpos[i][j] << ' ';
// cout << endl;
// }
if (a[maxpos[0]] < 0 && a[maxpos[1]] > 0) {
// cout<< "th1" << endl;
//truong hop co phan tu am va phan tu duong -> tich la so am nho nhat
sort(maxpos, maxpos + 2);
for (int i=0;i <= 1;i++) cout << maxpos[i] << ' ';
}
else {
// cout<< "th2" << endl;
//truong hop con lai -> tich la so duong be nhat
if(minpos[1][0] == -1) {
a[0] = minpos[0][0];
a[1] = minpos[0][1];
}
else {
a[0] = minpos[1][0];
a[1] = minpos[1][1];
}
sort(a, a + 2);
for (int i=0;i <= 1;i++) cout << a[i] << ' ';
}
return 0;
}