fork(1) download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<iostream>
  3. #include<vector>
  4. #include<algorithm>
  5. #include<set>
  6. #include<iostream>
  7. #include<string>
  8. #include<queue>
  9. #include <fstream>
  10. using namespace std;
  11. #define ll long long
  12. vector<int>v;
  13. struct el {
  14. int idx, val;
  15. el(int _idx, int _val) {
  16. idx = _idx;
  17. val = _val;
  18. }
  19. bool operator<(const el&r)const {
  20. if (val != r.val)
  21. return val > r.val;
  22. return idx < r.idx;
  23. }
  24. };
  25. int oo = 1e9;
  26. int main() {
  27. int k;
  28. scanf("%d", &k);
  29. vector<ifstream> files(k);
  30. priority_queue<el>pq;
  31. for (int i = 0,x; i < k; ++i) {
  32. files[i].open("file" + to_string(i) + ".txt");
  33. if (files[i] >> x)
  34. pq.push(el(i, x));
  35. }
  36. int count = 0;
  37. int total = 50;
  38. while (!pq.empty() && count!=total) {
  39. int srs = pq.top().idx;
  40. int x = pq.top().val;
  41. pq.pop();
  42. cout << x << endl;
  43. count++;
  44. while (files[srs] >> x && count!=total) {
  45. if (pq.empty() || pq.top().val>x) {
  46. cout << x << endl;
  47. count++;
  48. }
  49. else {
  50. pq.push(el(srs, x));
  51. break;
  52. }
  53. }
  54. }
  55.  
  56. for (int i = 0;i < k; ++i)
  57. files[i].close();
  58. }
  59.  
  60.  
Runtime error #stdin #stdout #stderr 0s 81600KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc