-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc1.cpp
More file actions
67 lines (56 loc) · 1.47 KB
/
c1.cpp
File metadata and controls
67 lines (56 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<int,int>>out;
int main(){
int t;
cin>>t;
while(t--){
ll a[50];
int n;
cin>>n;
out.clear();
bool positive=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>0)positive=1;
}
int step=0;
if(n==1)cout<<"0\n";
else if(positive){
int where;
for(int i=0;i<n;i++){
if(a[i]>0){where=i;break;}
}
while(a[where]<=20){
a[where]*=2;
step++;
out.push_back({where+1,where+1});
}
if(n!=1){
step+=2;
out.push_back({2,where+1});
out.push_back({2,where+1});
a[1]+=2*a[where];
}
for(int i=2;i<n;i++){
step+=2;
out.push_back({i+1,i});
out.push_back({i+1,i});
a[i]+=2*a[i-1];
}
}
else{
for(int i=n-2;i>=0;i--){
step++;
out.push_back({i+1,i+2});
a[i]+=a[i+1];
}
}
cout<<step<<"\n";
for(auto p:out){
cout<<p.first<<" "<<p.second<<"\n";
}
//for(int i=0;i<n;i++)cout<<a[i]<<" \n"[i==n-1];
}
}