-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56a7b40
commit e84556b
Showing
4 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package week012.day1210_PrefixSum; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class Bj2167 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int n = Integer.parseInt(st.nextToken()); | ||
int m = Integer.parseInt(st.nextToken()); | ||
|
||
int startX, startY, endX, endY; | ||
|
||
int[][] arr = new int[n][m]; | ||
for (int i = 0; i < n; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j = 0; j < m; j++) { | ||
arr[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
int k = Integer.parseInt(br.readLine()); | ||
|
||
for (int i = 0; i < k; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
startX = Integer.parseInt(st.nextToken()) - 1; | ||
startY = Integer.parseInt(st.nextToken()) - 1; | ||
endX = Integer.parseInt(st.nextToken()) - 1; | ||
endY = Integer.parseInt(st.nextToken()) - 1; | ||
|
||
int sum = calculateSum(arr, startX, startY, endX, endY); | ||
|
||
System.out.println(sum); | ||
} | ||
} | ||
|
||
public static int calculateSum(int[][] arr, int sX, int sY, int eX, int eY) { | ||
int sum = 0; | ||
|
||
for (int i = sX; i <= eX; i++) { | ||
for (int j = sY; j <= eY; j++) { | ||
sum += arr[i][j]; | ||
} | ||
} | ||
|
||
return sum; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package week012.day1210_PrefixSum; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class Bj2851 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int[] mushroom = new int[10]; | ||
int sum = 0; | ||
int[] total = new int[10]; | ||
|
||
for (int i = 0; i < 10; i++) { | ||
mushroom[i] = Integer.parseInt(br.readLine()); | ||
sum += mushroom[i]; | ||
total[i] = sum; | ||
} | ||
|
||
int small = 0; | ||
int large = 0; | ||
|
||
for (int i = 0; i < 10; i++) { | ||
if (total[i] > 100) { | ||
large = total[i]; | ||
small = total[i - 1]; | ||
break; | ||
} | ||
large = total[i]; | ||
} | ||
|
||
int smallDif = Math.abs(100 - small); | ||
int largeDif = Math.abs(100 - large); | ||
|
||
int result = smallDif < largeDif ? small : large; | ||
|
||
System.out.println(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package week012.day1210_PrefixSum; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class Bj30088 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int testCase = Integer.parseInt(br.readLine()); | ||
int[] sum = new int[testCase]; | ||
|
||
for(int i = 0; i < testCase; i++){ | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
int human = Integer.parseInt(st.nextToken()); | ||
int time = 0; | ||
for(int j = 0; j < human; j++){ | ||
time += Integer.parseInt(st.nextToken()); | ||
} | ||
sum[i] = time; | ||
} | ||
|
||
Arrays.sort(sum); | ||
int total = 0; | ||
int[] prefixSum = new int[testCase]; | ||
|
||
for(int i = 0; i < testCase; i++){ | ||
total += sum[i]; | ||
prefixSum[i] = total; | ||
} | ||
|
||
long result = 0; | ||
|
||
for(int i = 0; i < testCase; i++){ | ||
result += prefixSum[i]; | ||
System.out.println(sum[i]); | ||
} | ||
|
||
System.out.println(result); | ||
} | ||
} |