fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-6
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. using namespace std;
  28. // mylittledoge
  29.  
  30. int main() {
  31. cin.sync_with_stdio(0);
  32. cin.tie(0);
  33. int N,K;
  34. cin >> K >> N;
  35. vector< pair<int,int> > V(N);
  36. for(int i =0; i < N; i++) {
  37. cin >> V[i].ff >> V[i].ss;
  38. if(V[i].ff > V[i].ss) swap(V[i].ff,V[i].ss);}
  39. sort(V.begin(),V.end());
  40. vector<int> B(30000,0);
  41. int X =0;
  42. for(int i =N-1; i >= 0; i--) {
  43. int x =0;
  44. for(int j =V[i].ff+10000; j <= V[i].ss+10000; j++) x +=B[j];
  45. for(int j =V[i].ff+10000; j <= V[i].ss+10000; j++) {
  46. if(x >= K) break;
  47. if(B[j] == 0) B[j]++, x++, X++;}
  48. }
  49.  
  50. cout << X << "\n";
  51. for(int i =0; i < 30000; i++) if(B[i] == 1) cout << i-10000 << "\n";
  52. return 0;}
  53.  
  54. // look at my code
  55. // my code is amazing
Runtime error #stdin #stdout #stderr 0s 3480KB
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