Advertisement
Xoloter

Untitled

Dec 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. package AISDLab3;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.util.ArrayList;
  8.  
  9. public class E {
  10.  
  11.  
  12. public static void main(String[] args) throws IOException{
  13. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  14. // BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("test.in")));
  15.  
  16. int n = Integer.parseInt(reader.readLine());
  17. int[] nums = new int[n];
  18. for (int i = 0; i < n; i++) {
  19. nums[i] = Integer.parseInt(reader.readLine());
  20. }
  21. reader.close();
  22.  
  23. Dynamic[] d = new Dynamic[n];
  24. if (nums[0] > 100) {
  25. d[0] = new Dynamic(nums[0], 1);
  26. } else {
  27. d[0] = new Dynamic(nums[0], 0);
  28. }
  29.  
  30. ArrayList<Integer> days = new ArrayList<>();
  31.  
  32. for (int i = 1; i < n; i++) {
  33. if (d[i - 1].tickets == 0) {
  34. int q = 0;
  35. if (nums[i] > 100) {
  36. q = 1;
  37. }
  38. d[i] = new Dynamic(d[i - 1].cost + nums[i], q);
  39. } else {
  40. int t = nums[i];
  41. int next = 0;
  42. for (int j = i + 1; j < n; j++) {
  43. if (nums[j] > t) {
  44. t = -1;
  45. next++;
  46. }
  47. }
  48.  
  49. if (t == -1) {
  50. if (next + 1 == d[i - 1].tickets) {
  51. d[i] = new Dynamic(d[i - 1].cost, d[i - 1].tickets - 1);
  52. days.add(i + 1);
  53. } else {
  54. int q = 0;
  55. if (nums[i] > 100) {
  56. q = 1;
  57. }
  58. d[i] = new Dynamic(d[i - 1].cost + nums[i], d[i - 1].tickets + q);
  59. }
  60. } else {
  61. d[i] = new Dynamic(d[i - 1].cost, d[i - 1].tickets - 1);
  62. days.add(i + 1);
  63. }
  64. }
  65. }
  66.  
  67. System.out.println(d[n - 1].cost);
  68. System.out.println(d[n - 1].tickets + " " + days.size());
  69. for (int i: days) {
  70. System.out.println(i);
  71. }
  72.  
  73. }
  74.  
  75. private static class Dynamic {
  76. int cost;
  77. int tickets;
  78.  
  79. public Dynamic(int cost, int tickets) {
  80. this.cost = cost;
  81. this.tickets = tickets;
  82. }
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement