Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <cstdio>
  2. #include <queue>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main(void)
  7. {
  8. int tc;
  9. scanf("%d", &tc);
  10.  
  11. for (int tt = 1; tt <= tc; tt++) {
  12. int n, a, b;
  13. scanf("%d %d %d", &n, &a, &b);
  14. // n : 편지 갯수 , a이상의 편지가 오거나 b시간이 지나면 현재까지 온 편지 / 2갯수의 편지를 읽는다.
  15. queue<int> q, post;
  16. for (int i = 0; i < n; i++) {
  17. int time;
  18. scanf("%d", &time);
  19. q.push(time); // 온 편지마다 queue에 푸쉬
  20. post.push(time);
  21. }
  22.  
  23. // 시간이 지나간다
  24. int curTime = 0;
  25. vector<int> ans;
  26. queue<int> curPost;
  27. while (!q.empty()) {
  28. curTime++;
  29. if (!post.empty() && post.front() == curTime) {
  30. curPost.push(post.front());
  31. post.pop();
  32. }
  33.  
  34. // 현재 쌓인 우편물이 A개 이상이거나 가장 오래된 우편물이 b시간이 지나면
  35. if (curPost.size() >= a || curTime - q.front() == b) {
  36. double len = (double)curPost.size()/2;
  37. for (int i = 0; i < len; i++) {
  38. ans.push_back(curTime);
  39. q.pop();
  40. curPost.pop();
  41. }
  42. }
  43. }
  44.  
  45. printf("#%d ", tt);
  46. for(int i = 0;i<ans.size();i++)
  47. printf("%d ", ans[i]);
  48. puts("");
  49. }
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement