[softeer] 나무 공격
in Algorithm on Algorithm
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int xlen = sc.nextInt();
int ylen = sc.nextInt();
Map<Integer,Integer> box = new HashMap<>();
for(int x = 0 ; x < xlen ; x++){
box.put(x,0);
for(int y = 0 ; y < ylen ; y++){
box.put(x,box.get(x)+sc.nextInt());
}
}
int s1 = sc.nextInt();
int e1 = sc.nextInt();
int s2 = sc.nextInt();
int e2 = sc.nextInt();
for(int i = s1-1 ; i < e1 ; i++) box.put(i, box.get(i) - 1 );
for(int i = s2-1 ; i < e2 ; i++) box.put(i, box.get(i) - 1 );
int result = 0;
for(int x = 0 ; x < xlen ; x++){
result += box.get(x) > 0 ? box.get(x) : 0;
}
System.out.println(result);
}
}