ZCO-2013::Video Game

// CODE : ZCO14001
#include <bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false); cin.tie(0)

int main() {
boost;
long long int width, maxHeight;
cin >> width >> maxHeight;
long long int stack[width];

for (long long int i = 0; i < width; i++) {
cin >> stack[i];
}
long long int pointer{0};
bool hasBox{false};
while (true) {
int input;
cin >> input;

if (input == 1 and pointer > 0) {
pointer --;

} else if (input == 2 and pointer < width - 1) {
pointer ++;

} else if (input == 3 and hasBox == false and stack[pointer] != 0) {
stack[pointer] --;
hasBox = true;
} else if (input == 4 and hasBox == true and stack[pointer] != maxHeight) {
stack[pointer] ++;
hasBox = false;
} else if (input == 0) {
break;
}
}
for (long long int i = 0; i < width; i ++) {
cout << stack[i] << " ";
}
cout << endl;
return 0;
}

Comments

Popular posts from this blog

CodeChef::CSUB

How Recursion Works?

CodeChef::TREE2