hqt

Untitled

hqt
Jul 17th, 2013
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStreamWriter;
  6. import java.io.PrintWriter;
  7. import java.util.ArrayList;
  8. import java.util.Arrays;
  9. import java.util.LinkedList;
  10. import java.util.Queue;
  11. import java.util.Scanner;
  12.  
  13.  
  14. public class Main {
  15.  
  16. public static void main(String[] args) throws Exception {
  17. Main main = new Main();
  18. main.run();
  19. }
  20.  
  21.  
  22. boolean[] check = new boolean[2 * 100 - 1];
  23. int n = 0;
  24. int max = -1;
  25.  
  26. public void run() throws Exception {
  27. Scanner sc = null;
  28. PrintWriter pr = null;
  29.  
  30. pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  31. sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
  32. sc = new Scanner(new File("input.txt"));
  33.  
  34. int n = sc.nextInt();
  35. int[] A = new int[n+1];
  36. int[] P = new int[n+1];
  37. int[] N = new int[n+1];
  38. for (int i = 1; i <= n; i++) {
  39. A[i] = sc.nextInt();
  40. if (A[i] >= 0) {
  41. P[i] = P[i-1] + A[i];
  42. N[i] = N[i-1];
  43. }
  44. else {
  45. P[i] = P[i-1];
  46. N[i] = N[i-1] + 1;
  47. }
  48. }
  49.  
  50. int max = Integer.MIN_VALUE;
  51. int lo=0, hi=0;
  52. for (int i = 1; i < n ; i++) {
  53. for (int j = i + 1; j <= n; j++) {
  54. if (A[i] == A[j]) {
  55. // System.out.println("e: " + i + "\t" + j);
  56. // System.out.println("Bet: " + P[j] + "\t" + P[i-1]);
  57. int sum = P[j] - P[i-1];
  58. if (A[i] < 0) sum += 2 * A[i];
  59. //System.out.println("sum: " + sum);
  60. if (sum > max) {
  61. max = sum;
  62. lo = i;
  63. hi = j;
  64. }
  65. }
  66. }
  67. }
  68.  
  69. int res = lo-1 + N[hi-1] - N[lo] + n - hi;
  70. System.out.println(max + " "+ res);
  71. for (int i = 1; i < lo; i++) {
  72. System.out.print(i + " ");
  73. }
  74. for (int i = lo + 1; i <= hi - 1; i++) {
  75. if (A[i] < 0) System.out.print(i + " ");
  76. }
  77. for (int i = hi + 1; i <= n; i++) {
  78. System.out.print(i + " ");
  79. }
  80. pr.close();
  81. sc.close();
  82.  
  83. }
  84.  
  85. public void dfs(int u) {
  86. check[u] = true;
  87. if (u > max) max = u;
  88. if (u > 2 * n - 2) return;
  89. for (int i = 0; i <= Math.min(u, n); i++) {
  90. System.out.println("should dfs: " + u + "\t" + i + "\t" + n);
  91. if (!check[u - 2*i + n]) dfs(u - 2 * i + n);
  92. }
  93. }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment