You are given an array aa consisting of nn integers. You can perform the following operations with it:
- Choose some positions ii and jj (1≤i,j≤n,i≠j1≤i,j≤n,i≠j), write the value of ai⋅ajai⋅aj into the jj-th cell and remove the number from the ii-th cell;
- Choose some position ii and remove the number from the ii-th cell (this operation can be performed no more than once and at any point of time, not necessarily in the beginning).
The number of elements decreases by one after each operation. However, the indexing of positions stays the same. Deleted numbers can't be used in the later operations.
Your task is to perform exactly n−1n−1 operations with the array in such a way that the only number that remains in the array is maximum possible. This number can be rather large, so instead of printing it you need to print any sequence of operations which leads to this maximum number. Read the output format to understand what exactly you need to print.
Input
The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of elements in the array.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109) — the elements of the array.
Output
Print n−1n−1 lines. The kk-th line should contain one of the two possible operations.
The operation of the first type should look like this: 1 ik jk1 ik jk, where 11 is the type of operation, ikik and jkjk are the positions of the chosen elements.
The operation of the second type should look like this: 2 ik2 ik, where 22 is the type of operation, ikik is the position of the chosen element. Note that there should be no more than one such operation.
If there are multiple possible sequences of operations leading to the maximum number — print any of them.
有一tuo数量为n的数列,你有两种操作,一种是删掉某个位置的值,一个是吧i位置的数乘到j位置上,再把i位置上的数删除,求怎么样操作能使最后留下的数最大~~。对了。。删除操作只能用一次;
通过贪心可得出,这个删除操作一定是用在删除0以及(奇数上那个的负数)而造成的影响上,所以把所有的0以及最大的负数(负数数量为奇数时)乘起来再删掉就行了。其他的按步骤操作即可。
#include<bits/stdc++.h>
using namespace std;
const int inf =0x3f3f3f3f;
int n,m[200005];
int main(){
scanf("%d",&n);
int fsum=0;int minn=-0x3f3f3f3f;
int zero=0;
for(int i=1;i<=n;i++){
scanf("%d",&m[i]);
if(m[i]==0){
zero++;
}
if(m[i]<0){
minn=max(minn,m[i]);
fsum++;
}
}
if(fsum%2){
int za=inf;int a=inf;
int spot=1,res=0;
for(int i=1;i<=n;i++){
if(m[i]==0||(m[i]==minn&&spot==1)){
if(m[i]==minn){
spot=0;
}
if(za==inf){
za=i;
}
else{
res++;
printf("1 %d %d\n",za,i);
za=i;
}
}
else{
if(a==inf){
a=i;
}
else{
res++;
printf("1 %d %d\n",a,i);
a=i;
}
}
}
if(res!=n-1){
printf("2 %d\n",za);
}
}
else{
int za=inf;int a=inf;
int res=0;
for(int i=1;i<=n;i++){
if(m[i]==0){
if(za==inf){
za=i;
}
else{
res++;
printf("1 %d %d\n",za,i);
za=i;
}
}
else{
if(a==inf){
a=i;
}
else{
res++;
printf("1 %d %d\n",a,i);
a=i;
}
}
}
if(res!=n-1){
printf("2 %d\n",za);
}
}
return 0;
}