fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. int n;
  11. n = in.nextInt();
  12. int a[][];
  13. int b[] = new int [n];
  14. a = new int[n][];
  15. for(int i = 0; i < n; i++){
  16. a[i] = new int [n];
  17. b[i] = 0;
  18. for(int j = 0; j < n; j++){
  19. a[i][j] = in.nextInt();
  20. }
  21. }
  22. for(int i = 0; i < n; i++){
  23. if(a[i][i] < 0){
  24. for(int j = 0; j < i; j++){
  25. if(a[i][j] < 0) break;
  26. b[i]+=a[i][j];
  27. }
  28. }
  29. else{
  30. int k;
  31. for(k = 0; k < n; k++){
  32. if(a[i][k] >= 0) break;
  33. }
  34. for(int j = k; j < n; j++){
  35. b[i]+=a[i][j];
  36. }
  37. }
  38. }
  39. for(int i = 0; i < n; i++){
  40. System.out.print(b[i] + " ");
  41. }
  42. }
  43. }
Success #stdin #stdout 0.14s 321280KB
stdin
3
1 -2 3
-7 -3 0
5 5 2
stdout
2 0 12