fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define vi vector<int>
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define ii pair<int , int>
  9. #define pq priority_queue
  10. #define iii pair<int , pair<int , int>>
  11. #define fo(i,l,r) for(int i=l;i<=r;i++)
  12. #define fod(i,r,l) for(int i=r;i>=l;i--)
  13. #define fill(f,x) memset(f,x,sizeof(f))
  14. #define NAME "file"
  15.  
  16. const int N = 2e5 + 5, mod = 1e9 + 7;
  17. int n , U , V , a[21] , b[21] , p[21] , ans = 0;
  18.  
  19. void sol(int i)
  20. {
  21. if (i > n)
  22. {
  23. int wei = 0 , val = 0;
  24. for (int j = 0 ; j <= n ; j++)
  25. {
  26. wei += p[j] * a[j]; // giống if (p[j]) wei += a[j]
  27. val += p[j] * b[j];
  28. }
  29. if (wei >= U && wei <= V)
  30. ans = max(ans , val);
  31. }
  32. else
  33. {
  34. for (int j = 0 ; j <= 1 ; j++)
  35. {
  36. p[i] = j;
  37. sol(i + 1);
  38. }
  39. }
  40. }
  41.  
  42. signed main()
  43. {
  44. ios_base::sync_with_stdio(0);
  45. cin.tie(0); cout.tie(0);
  46. //freopen(NAME".INP" , "r" , stdin);
  47. //freopen(NAME".OUT" , "w" , stdout);
  48.  
  49. cin >> n >> U >> V;
  50. for (int i = 1 ; i <= n ; i++)
  51. cin >> a[i] >> b[i];
  52. sol(1);
  53. cout << ans;
  54. }
  55. // haronnee_
Success #stdin #stdout 0s 5332KB
stdin
Standard input is empty
stdout
Standard output is empty