#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in array<int, 2>
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
signed main()
{
fast();
int n, k; cin >> n >> k;
vector<int> a(n+1);
assert(n%2 == 0); assert(k == 2);
for(int i = 1; i <= n; i++)
cin >> a[i];
vector<in> op;
while(true)
{
bool check = true;
for(int i = 1; i <= n; i++)
{
if(a[i] >= 2)
check = false;
}
if(check)
break;
int K = INF;
for(int i = 1; i <= n; i++)
{
if(a[i] == 0)
{
op.pb({1, i});
a[i]+=2;
}
K = min(K, a[i]);
}
for(int i = 1; i <= n; i++)
a[i]-=K;
}
int ok = 0;
for(int i = 1; i <= n; i++)
ok+=a[i];
if(ok%2)
{
cout << "-1\n";
return 0;
}
while(true)
{
bool check = true;
for(int i = 1; i <= n; i++)
{
if(a[i] > 0)
check = false;
}
if(check)
break;
bool scheck = true;
for(int i = 1; i <= n; i++)
{
if(a[i] == 0)
continue;
if(i%2 == 0)
scheck = false;
}
if(scheck)
{
//all ppl at odd position.
/*cout << "Triggered" << endl;
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;*/
bool fst = 0;
for(int i = 1; i <= n; i+=2)
{
if(a[i] == 0)
{
op.pb({2, i});
op.pb({2, i});
a[i] = a[i+1] = 1;
}
if(fst)
op.pb({2, i});
else
{
op.pb({1, i});
op.pb({1, i+1});
fst = 1;
a[i] = 2;
a[i+1] = 1;
}
}
int K = INF;
for(int i = 1; i <= n; i++)
{
if(a[i] == 0)
{
op.pb({1, i});
a[i]+=2;
}
K = min(K, a[i]);
}
for(int i = 1; i <= n; i++)
{
a[i]-=K;
//cout << a[i] << " ";
}
cout << endl;
continue;
}
int K = INF;
for(int i = 1; i <= n; i++)
{
if(a[i] == 1)
{
K = min(K, 1ll);
continue;
}
if(a[i+1] == 0)
{
op.pb({2, i});
a[i] = a[i+1] = 1;
}
else
{
op.pb({1, i});
a[i] = 2;
}
K = min(K, a[i]);
}
for(int i = 1; i <= n; i++)
{
a[i]-=K;
//cout << a[i] << " ";
}
//cout << endl;
}
cout << op.size() << "\n";
for(auto [i, x]: op)
cout << i << " " << x << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |