Guest User

Untitled

a guest
Jun 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. # include <iostream>
  2. # include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. struct pole
  7. {
  8. int first;
  9. int last;
  10. int index;
  11. };
  12.  
  13. //int out[10000];
  14. //pole column[10000];
  15.  
  16. bool fun ( pole p1, pole p2 ) { return ( p1.last < p2.last ); }
  17.  
  18. int main()
  19. {
  20. int n,i,index;
  21. cin >> n;
  22. int *out = new int[n];
  23. pole *column = new pole[n];
  24. bool *empty = new bool[n];
  25. for ( i=0; i<n; i++)
  26. {
  27. cin >> column[i].first;
  28. cin >> column[i].last;
  29.  
  30. out[i] = -1;
  31. column[i].index = i;
  32. empty[i] = true;
  33. }
  34.  
  35. sort(&column[0],&column[n],fun);
  36.  
  37. index = 0;
  38. for ( i=0; i<n; i++ )
  39. {
  40. while ( column[i].first <= column[i].last )
  41. {
  42. if ( empty[column[i].first] )
  43. {
  44. out[column[i].index] = column[i].first;
  45. empty[column[i].first] = false;
  46. break;
  47. }
  48. column[i].first++;
  49. }
  50. }
  51. bool ok = true;
  52. for (i=0;i<n;i++)
  53. if ( out[i] == -1 )
  54. {
  55. ok = false;
  56. break;
  57. }
  58.  
  59. if ( ok )
  60. for (i=0;i<n;i++)
  61. cout << out[i] << endl;
  62. else
  63. cout << "NIE";
  64.  
  65. //system("Pause");
  66. return 0;
  67. }
Add Comment
Please, Sign In to add comment