fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. #include <stdio.h>
  5.  
  6. int main(void) {
  7. int stasiun_cnt, robot_cnt;
  8. if (scanf("%d %d", &stasiun_cnt, &robot_cnt) != 2) return 0;
  9.  
  10. long long harga_s[105];
  11. for (int x = 1; x <= stasiun_cnt; x++) {
  12. scanf("%lld", &harga_s[x]);
  13. }
  14.  
  15. long long bobot_r[2005];
  16. for (int x = 1; x <= robot_cnt; x++) {
  17. scanf("%lld", &bobot_r[x]);
  18. }
  19.  
  20. int slot_isi[105] = {0};
  21. int status_posisi[2005] = {0};
  22.  
  23. int antrean[2005];
  24. int f_idx = 0, r_idx = 0;
  25.  
  26. long long kas_bengkel = 0;
  27.  
  28. int total_kejadian = 2 * robot_cnt;
  29. for (int ev = 0; ev < total_kejadian; ev++) {
  30. int log_ev;
  31. scanf("%d", &log_ev);
  32.  
  33. if (log_ev > 0) {
  34. int cur_r = log_ev;
  35.  
  36. int target_slot = -1;
  37. for (int s = 1; s <= stasiun_cnt; s++) {
  38. if (slot_isi[s] == 0) {
  39. target_slot = s;
  40. break;
  41. }
  42. }
  43.  
  44. if (target_slot != -1) {
  45. slot_isi[target_slot] = cur_r;
  46. status_posisi[cur_r] = target_slot;
  47. kas_bengkel += bobot_r[cur_r] * harga_s[target_slot];
  48. } else {
  49. antrean[r_idx++] = cur_r;
  50. }
  51.  
  52. } else {
  53. int cur_r = -log_ev;
  54.  
  55. int released_slot = status_posisi[cur_r];
  56. slot_isi[released_slot] = 0;
  57. status_posisi[cur_r] = 0;
  58.  
  59. if (f_idx < r_idx) {
  60. int next_r = antrean[f_idx++];
  61. slot_isi[released_slot] = next_r;
  62. status_posisi[next_r] = released_slot;
  63. kas_bengkel += bobot_r[next_r] * harga_s[released_slot];
  64. }
  65. }
  66. }
  67.  
  68. printf("%lld\n", kas_bengkel);
  69. return 0;
  70. }
  71. }
  72.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty