|
| 1 | +#include <cmath> |
| 2 | +#include <set> |
| 3 | +#include <list> |
| 4 | +//#include <unordered_set> |
| 5 | +//#include <hash_map> |
| 6 | +#include <climits> |
| 7 | +#include <queue> |
| 8 | +#include <vector> |
| 9 | +#include <map> |
| 10 | +#include <set> |
| 11 | +#include <cstdlib> |
| 12 | +#include <fstream> |
| 13 | +#include <iomanip> |
| 14 | +#include <iostream> |
| 15 | +#include <sstream> // istringstream buffer(myString); |
| 16 | +#include <stack> |
| 17 | +#include <algorithm> |
| 18 | +#include <cstring> |
| 19 | +#include <cassert> |
| 20 | +using namespace std; |
| 21 | +#define bit(x,i) (x&(1<<i)) |
| 22 | +#define lowb(t) (t &(-t)) |
| 23 | +#define pow2(x) (1<<x) |
| 24 | +//#define max(a,b) (a<b?b:a) |
| 25 | +//#define abs(x) (x<0?-x:x) |
| 26 | +#define IN(i,l,r) (l<i&&i<r) |
| 27 | +#define LINR(i,l,r) (l<=i&&i<=r) |
| 28 | +#define LIN(i,l,r) (l<=i&&i<r) |
| 29 | +#define INR(i,l,r) (l<i&&i<r) |
| 30 | +#define F(i,L,R) for (int i = L; i < R; i++) |
| 31 | +#define FE(i,L,R) for (int i = L; i <= R; i++) |
| 32 | +#define FF(i,L,R) for (int i = L; i > R; i--) |
| 33 | +#define FFE(i,L,R) for (int i = L; i >= R; i--) |
| 34 | +#define char2Int(c) (c-'0') |
| 35 | +#define lastEle(vec) vec[vec.size()-1] |
| 36 | +#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) |
| 37 | +#define clr(a,x) memset(a,x,sizeof(a)) |
| 38 | +#define getI(a) scanf("%d", &a) |
| 39 | +#define getII(a,b) scanf("%d%d", &a, &b) |
| 40 | +#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c) |
| 41 | +#define getS(x) scanf("%s", x); |
| 42 | +#define SZ(x) ((int)((x).size())) |
| 43 | +#define REMAX(a,b) (a)=max((a),(b)); |
| 44 | +#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl; |
| 45 | +#define REMIN(a,b) (a)=min((a),(b)); |
| 46 | +#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) |
| 47 | +#define ALL(t) t.begin(),t.end() |
| 48 | +#define ll long long |
| 49 | +#define ull unsigned long long |
| 50 | +#define ui unsigned int |
| 51 | +#define us unsigned short |
| 52 | +#define IOS ios_base::sync_with_stdio(0); |
| 53 | +#define pb push_back |
| 54 | +#define INF 1001001001 |
| 55 | +#define PI 3.1415926535897932384626 |
| 56 | +#define mp make_pair |
| 57 | +#define ll long long |
| 58 | +#define fi first |
| 59 | +#define se second |
| 60 | +#define root(x) ((int)sqrt((double)x)) |
| 61 | +#define wez(n) int (n); scanf("%d",&(n)); |
| 62 | +#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m)); |
| 63 | +#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k)); |
| 64 | +inline void pisz(int n) { printf("%d\n",n); } |
| 65 | +#define TESTS wez(testow)while(testow--) |
| 66 | +#define whileZ int T; getI(T); while(T--) |
| 67 | +#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ') |
| 68 | +#define printM(a,n,m) F(i,0,n){ F(j,0,m) cout << a[i][j] << ' '; cout << endl;} |
| 69 | +#define printV(a) printA(a,0,(int)a.size()-1); |
| 70 | +#define printVV(a) F(i,0,a.size()) {F(j,0,a[i].size())cout << a[i][j] << ' '; cout << endl;} |
| 71 | +#define MAXN 10000 |
| 72 | +#define sz(a) int((a).size()) |
| 73 | +#define pb push_back |
| 74 | +#define all(c) (c).begin(),(c).end() |
| 75 | +#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) |
| 76 | +#define present(c,x) ((c).find(x) != (c).end()) |
| 77 | +#define cpresent(c,x) (find(all(c),x) != (c).end()) |
| 78 | +template<class T> string tos(T n) { stringstream ss; ss << n; return ss.str(); } |
| 79 | +#define tiny (double)1e-13 |
| 80 | +#define close(x,y) (abs(x-y)<tiny) |
| 81 | +typedef int elem_t; |
| 82 | +typedef vector<int> vi; |
| 83 | +typedef vector<vi> vvi; |
| 84 | +typedef pair<int,int> ii; |
| 85 | +template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";} |
| 86 | +template<typename T> ostream& operator<<(ostream &s,vector<T> t){F(i,0,SZ(t))s<<t[i]<<" ";return s; } |
| 87 | +int gcd(int a,int b){return a?gcd(b%a,a):b;} |
| 88 | +ll gcd(ll a,ll b){return a?gcd(b%a,a):b;} |
| 89 | +ll powmod(ll a,ll p,ll m){ll r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;} |
| 90 | +struct node{ |
| 91 | + int h, m; |
| 92 | + bool operator<(const node& other)const{ |
| 93 | + return m > other.m; |
| 94 | + //return h < other.h; |
| 95 | + } |
| 96 | + node(int h, int m):h(h), m(m){ |
| 97 | + |
| 98 | + } |
| 99 | +}; |
| 100 | +bool va[2001], vb[2001]; |
| 101 | +vector<node> a, b; |
| 102 | +int main ( int argc, char *argv[] ) { |
| 103 | + wez2(n,x); |
| 104 | + F(i,0,n){ |
| 105 | + wez3(t, h, m); |
| 106 | + if (t == 0) a.push_back(node(h,m)); |
| 107 | + else b.push_back(node(h,m)); |
| 108 | + } |
| 109 | + sort(a.begin(), a.end()); |
| 110 | + sort(b.begin(), b.end()); |
| 111 | + |
| 112 | + |
| 113 | + int cnt = 0; |
| 114 | + clr(va, 0); |
| 115 | + clr(vb, 0); |
| 116 | + bool turn = 0; |
| 117 | + int xx = x; |
| 118 | + while(true){ |
| 119 | + int oldCnt = cnt; |
| 120 | + if (turn){ |
| 121 | + F(i,0,b.size()){ |
| 122 | + if (!vb[i] && xx >= b[i].h){ |
| 123 | + xx += b[i].m; |
| 124 | + vb[i] = true; |
| 125 | + cnt++; |
| 126 | + break; |
| 127 | + } |
| 128 | + } |
| 129 | + }else{ |
| 130 | + F(i,0,a.size()){ |
| 131 | + if (!va[i] && xx >= a[i].h){ |
| 132 | + xx += a[i].m; |
| 133 | + va[i] = true; |
| 134 | + cnt++; |
| 135 | + break; |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + if(cnt == oldCnt) break; |
| 140 | + turn = !turn; |
| 141 | + } |
| 142 | + int cnt1 = cnt; |
| 143 | + cnt = 0; |
| 144 | + clr(va, 0); |
| 145 | + clr(vb, 0); |
| 146 | + turn = 1; |
| 147 | + xx = x; |
| 148 | + while(true){ |
| 149 | + int oldCnt = cnt; |
| 150 | + if (turn){ |
| 151 | + F(i,0,b.size()){ |
| 152 | + if (!vb[i] && xx >= b[i].h){ |
| 153 | + xx += b[i].m; |
| 154 | + vb[i] = true; |
| 155 | + cnt++; |
| 156 | + break; |
| 157 | + } |
| 158 | + } |
| 159 | + }else{ |
| 160 | + F(i,0,a.size()){ |
| 161 | + if (!va[i] && xx >= a[i].h){ |
| 162 | + xx += a[i].m; |
| 163 | + va[i] = true; |
| 164 | + cnt++; |
| 165 | + break; |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + if(cnt == oldCnt) break; |
| 170 | + turn = !turn; |
| 171 | + } |
| 172 | + cout << max(cnt, cnt1) << endl; |
| 173 | + return EXIT_SUCCESS; |
| 174 | +} |
0 commit comments