Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /**
  2. * Tittle: 10154 - Weights and Measures
  3. * Author: Cheng-Shih, Wong
  4. * Date: 2015/04/14
  5. */
  6.  
  7. // include files
  8. #include <bits/stdc++.h>
  9.  
  10. using namespace std;
  11.  
  12. // definitions
  13. #define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i )
  14. #define clr(x,v) memset( x, v, sizeof(x) )
  15. #define N 6000
  16.  
  17. class Turtle {
  18. public:
  19. int w, s;
  20.  
  21. Turtle( int _w=0, int _s=0 ): w(_w), s(_s) {}
  22.  
  23. const bool operator<( const Turtle &op ) const {
  24. return s < op.s;
  25. }
  26. };
  27.  
  28. typedef priority_queue<int> PQI;
  29.  
  30. // declarations
  31. Turtle tt[N];
  32. int n;
  33. int allw;
  34.  
  35. // functions
  36.  
  37.  
  38. // main function
  39. int main( void )
  40. {
  41.  
  42. // input
  43. n = 0;
  44.  
  45. while( scanf( "%d%d", &tt[n].w, &tt[n].s )==2 ) ++n;
  46.  
  47. // solve
  48. sort( tt, tt+n );
  49.  
  50. allw = 0;
  51. PQI pq;
  52.  
  53. FOR( i, 0, n-1 ) {
  54. allw += tt[i].w;
  55. pq.push( tt[i].w );
  56. if( allw > tt[i].s ) {
  57. allw -= pq.top();
  58. pq.pop();
  59. }
  60. }
  61.  
  62. // output
  63. printf( "%d\n", pq.size() );
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement