#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; template struct BIT{ //1-indexed vector bit; int size; BIT(int n):size(n), bit(n+1, 0){} T sum(int i){ T s=0; while(i>0){ s+=bit[i]; i-=(i&(-i)); } return s; } void add(int i, T x){ while(i<=size){ bit[i]+=x; i+=(i&(-i)); } } }; int main() { int n, w; ll h; cin>>n>>w>>h; vector vl[100010], vr[100010]; ll b[100010]; for(int i=0; i>a>>b[i]>>x; vl[x].push_back(i); vr[a+x].push_back(i); } BIT bit(n+1); int c[2]={}; for(int i=1; i<=w; i++){ for(auto j:vl[i]){ bit.add(j+1, b[j]); } for(auto j:vr[i]){ bit.add(j+1, -b[j]); } int l=-1, r=n+1; while(r-l>1){ int m=(l+r)/2; if(bit.sum(m+1)>=h) r=m; else l=m; } c[r&1]++; } //cerr<c[1]) cout<<"A"<