1.
import java.util.Scanner;
public class Main {public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
int[] arr = new int[num];
for(int i = 0; i < num; i++){
arr[i] = in.nextInt();
}
int result = 0;
for(int i = 0; i < num; i++){
if(i < num - 1){
int temp = arr[i + 1] - arr[i];
if(temp < 0){
temp = 0 - temp;
}
if(temp > result){
result = temp;
}
}
if(i == num - 1){
int temp = arr[i] - arr[i - 1];
if(temp < 0){
temp = 0 - temp;
}
if(temp > result){
result = temp;
}
}
}
System.out.println(result);
}
}
2.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
int[][] arr = {{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,68,69,70},
{71,72,73,74,75},
{76,77,78,79,80},
{81,82,83,84,85},
{86,87,88,89,90},
{91,92,93,94,95},
{96,97,98,99,100}};
int[][] visited = new int[20][5];
int[] buy = new int[num];
for(int i = 0; i < num; i++){
buy[i] = in.nextInt();
}
for(int i = 0; i < num; i++){
int temp = buy[i];
for(int j = 0; j < 20; j++){
int k = 0;
int place = 0;
while(place <= 4 && visited[j][place] == 1){
place++;
}
k = place;
int er = 0;
while(k <= 4 && visited[j][k] == 0){
er++;
k++;
}
if(er >= temp){
int number = place + temp;
for(int q = place; q < number; q++){
visited[j][q] = 1;
if(q == number - 1){
System.out.println(arr[j][q]);
}
else {
System.out.print(arr[j][q]+" ");
}
}
break;
}
}
}
}
}
3.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
in.nextLine();
int attacker = 30;
int defender = 30;
Point[] attack = new Point[7];
Point[] defend = new Point[7];
int[] attack_vis = new int[7];
int[] defend_vis = new int[7];
int flag = 0;
int result_final = 0;
for(int i = 0; i < num; i++){
String way = in.next();
if(way.equals("summon")){
int pos = in.nextInt();
pos--;
int att = in.nextInt();
int fit = in.nextInt();
Point temp = new Point(att, fit);
if(flag == 0){
if(attack_vis[pos] == 0){
attack_vis[pos] = 1;
attack[pos] = temp;
}
else{
int temp1 = pos + 1;
while(attack_vis[temp1] == 1){
temp1++;
}
for(int j = temp1; j >= pos; j--){
attack_vis[temp1] = 1;
if(j > pos){
attack[j] = attack[j - 1];
}
else {
attack[j] = temp;
}
}
}
}
else{
if(defend_vis[pos] == 0){
defend_vis[pos] = 1;
defend[pos] = temp;
}
else{
int temp1 = pos + 1;
while(defend_vis[temp1] == 1){
temp1++;
}
for(int j = temp1; j >= pos; j--){
defend_vis[temp1] = 1;
if(j > pos){
defend[j] = defend[j - 1];
}
else {
defend[j] = temp;
}
}
}
}
}
else if(way.equals("attack")){
int pos = in.nextInt();
pos--;
int aim = in.nextInt();
if(flag == 0){
Point temp = attack[pos];
int att1 = temp.att;
int fit1 = temp.fit;
if(aim == 0){
defender = defender - att1;
if(defender <= 0){
result_final = 1;
break;
}
}
else {
aim--;
Point temp1 = defend[aim];
int att2 = temp1.att;
int fit2 = temp1.fit;
if(att2 < fit1){
fit1 = fit1 - att2;
temp.fit = fit1;
}
else {
int pos1 = pos + 1;
while(attack_vis[pos1] != 0){
pos1++;
}
pos1--;
attack_vis[pos1] = 0;
for(int j = pos1; j > pos; j--){
attack[j - 1] = attack[j];
}
}
if(att1 < fit2){
fit2 = fit2 - att1;
temp1.fit = fit2;
}
else {
int pos1 = aim + 1;
while(defend_vis[pos1] != 0){
pos1++;
}
pos1--;
defend_vis[pos1] = 0;
for(int j = pos1; j > aim; j--){
defend[j - 1] = defend[j];
}
}
}
}
else{
Point temp = defend[pos];
int att1 = temp.att;
int fit1 = temp.fit;
if(aim == 0){
attacker = attacker - att1;
if(attacker <= 0){
result_final = -1;
break;
}
}
else {
aim--;
Point temp1 = attack[aim];
int att2 = temp1.att;
int fit2 = temp1.fit;
if(att2 < fit1){
fit1 = fit1 - att2;
temp.fit = fit1;
}
else {
int pos1 = pos + 1;
while(defend_vis[pos1] != 0){
pos1++;
}
pos1--;
defend_vis[pos1] = 0;
for(int j = pos1; j > pos; j--){
defend[j - 1] = defend[j];
}
}
if(att1 < fit2){
fit2 = fit2 - att1;
temp1.fit = fit2;
}
else {
int pos1 = aim + 1;
while(attack_vis[pos1] != 0){
pos1++;
}
pos1--;
attack_vis[pos1] = 0;
for(int j = pos1; j > aim; j--){
attack[j - 1] = attack[j];
}
}
}
}
}
else if(flag == 0){
flag = 1;
}
else if(flag == 1){
flag = 0;
}
}
System.out.println(result_final);
System.out.println(attacker);
int flag_f = 0;
while(attack_vis[flag_f] != 0){
flag_f++;
}
System.out.print(flag_f+" ");
for(int i = 0; i < flag_f;i++){
if(i == flag_f - 1){
System.out.println(attack[i].fit);
}
else {
System.out.print(attack[i].fit+" ");
}
}
System.out.println(defender);
int flag_g = 0;
while(defend_vis[flag_g] != 0){
flag_g++;
}
System.out.print(flag_g+" ");
for(int i = 0; i < flag_g;i++){
if(i == flag_g - 1){
System.out.println(defend[i].fit);
}
else {
System.out.print(defend[i].fit+" ");
}
}
}
}
class Point{
int att;
int fit;
public Point(int att, int fit) {
super();
this.att = att;
this.fit = fit;
}
}