fork download
  1. /***********Template Starts Here***********/
  2. #include <bits/stdc++.h>
  3.  
  4. #define pb push_back
  5. #define nl puts ("")
  6. #define sp printf ( " " )
  7. #define phl printf ( "hello\n" )
  8. #define ff first
  9. #define ss second
  10. #define POPCOUNT __builtin_popcountll
  11. #define RIGHTMOST __builtin_ctzll
  12. #define LEFTMOST(x) (63-__builtin_clzll((x)))
  13. #define MP make_pair
  14. #define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
  15. #define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
  16. #define CLR(x,y) memset(x,y,sizeof(x))
  17. #define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
  18. #define MIN(a,b) ((a)<(b)?(a):(b))
  19. #define MAX(a,b) ((a)>(b)?(a):(b))
  20. #define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
  21. #define SQ(x) ((x)*(x))
  22. #define ABS(x) ((x)<0?-(x):(x))
  23. #define FABS(x) ((x)+eps<0?-(x):(x))
  24. #define ALL(x) (x).begin(),(x).end()
  25. #define LCM(x,y) (((x)/gcd((x),(y)))*(y))
  26. #define SZ(x) ((vlong)(x).size())
  27. #define NORM(x) if(x>=mod)x-=mod;
  28.  
  29. using namespace std;
  30.  
  31. typedef long long vlong;
  32.  
  33. /***********Template Ends Here***********/
  34.  
  35. int main () {
  36.  
  37. int kase;
  38. scanf ( "%d", &kase );
  39.  
  40. while ( kase-- ) {
  41. vlong n, m;
  42. scanf ( "%lld %lld", &n, &m );
  43.  
  44. int critical = n - 1;
  45. m -= n - 1;
  46.  
  47. int k = 1;
  48. while ( m > 0 ) {
  49.  
  50. ///Remove edges
  51. m -= k;
  52. if ( k == 1 ) { ///Special case
  53. critical -= 2;
  54. }
  55. else {
  56. critical -= 1;
  57. }
  58.  
  59. k++;
  60. }
  61.  
  62. printf ( "%d\n", critical );
  63. }
  64.  
  65. return 0;
  66. }
  67.  
Time limit exceeded #stdin #stdout 5s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty