Problem:
プログラミングコンテスト
白虎大学では毎年プログラミングコンテストが開催されています。チームの総数をNとしたとき、チームには1からNのチームIDがそれぞれ割り当てられています。コンテストは全てのチームの得点が0の状態から開始し、L秒間連続して行われます。
今年のコンテストは、テレビで中継されることになりました。コンテストの間テレビに映るのは、その時点で最も得点の高いチームだけです。ただし、該当するチームが複数いるときは、その中でチームIDの一番小さいチームが映ります。映すべきチームが変わると、瞬時にカメラが切り替わります。
あなたはコンテストのログを入手しました。ログには、あるチームの得点が変化した時のレコードがすべて含まれています。各レコードは「チーム
d
がコンテスト開始
t
秒後の時点で
x
点獲得した」という形式で与えられています。なお、減点される場合もあるので、現在の得点が0より小さくなることもあります。
コンテストのログを入力とし、コンテスト開始から終了までの間にテレビに映った時間が最も長いチームのIDを報告するプログラムを作成してください。
入力
入力は1つのデータセットからなる。入力は以下の形式で与えられる。
N
R
L
d
1
t
1
x
1
d
2
t
2
x
2
:
d
R
t
R
x
R
１行目は３つの整数からなる。
N
(2 ≤
N
≤ 100000)はチーム数、
R
(0 ≤
R
≤ 1000000)はログに含まれるレコードの数である。
L
(1 ≤
L
≤ 1000000)はコンテストの時間（長さ）を表す。続く
R
行に各レコードの情報が与えられる。各レコードはチーム
d
i
(1 ≤
d
i
≤
N
)がコンテスト開始
t
i
(0 <
t
i
<
L
)秒後の時点で
x
i
(-1000 ≤
x
i
≤ 1000)点獲得あるいは減点されたことを示す。ただし、
t
i
,
x
i
は整数であり、
t
i-1
≤
t
i
である。
出力
コンテスト開始から終了までの間にテレビに映った時間が最も長いチームのIDを１行に出力する。ただし、最も長いチームが複数あるときは、その中でチームIDの一番小さいチームを出力する。
入力例 1
3 4 600
3 100 5
1 200 10
2 400 20
3 500 20
出力例 1
1
入力例 2
3 5 600
3 100 5
1 200 10
2 300 30
1 400 -8
2 400 -27
出力例 2
3

Submitted solutions:

code_snippet: // 7
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i =(a); i <(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = (1<<29);
const bool debug = 0;

struct SegTree {
	pii init_val;
	int n;
	vector<pii> node;
	
	SegTree(int _n, pii init_val) : init_val(init_val) {
		n = 1;
		while (n < _n) n *= 2;
		node.resize(2 * n - 1, init_val);
	}
	
	void add(int i, int x) {
		i += n - 1;
		node[i].fi += x;
		
		while (i > 0) {
			i = (i - 1) / 2;
			node[i] = max(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}
	
	void update(int i, pii x) {
		i += n - 1;
		chmax(node[i], x);
		
		while (i > 0) {
			i = (i - 1) / 2;
			node[i] = max(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}
	
	pii query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return node[k];
		return max(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
	}
};

int N, R, L;
int cnt[112345];

int main() {
	cin >> N >> R >> L;
	
	int lastt = 0;
	SegTree seg(N, pii(-INF, 0));
	
	REP(i, N) seg.update(i, pii(0, -i));
	
	REP(i, R) {
		int d, t, x;
		scanf("%d %d %d", &d, &t, &x);
		d--;
		
		cnt[-seg.query(0, N).se] += t - lastt;
		seg.add(d, x);
		lastt = t;
	}
	cnt[-seg.query(0, N).se] += L - lastt;
	
	int ans = -INF, ansp = 0;
	REP(i, N) if (chmax(ans, cnt[i])) ansp = i + 1;
	
	cout << ansp << endl;
	
	return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 5412
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    

    int N,R,L;
    cin>>N>>R>>L;
    
    vector<int> A(N,0);
    set<pair<int,int>> st;
    vector<int> ans(N,0);
    rep(i,N) st.insert({-A[i], i});
    int mae=0;
    rep(i,R){
        int d,t,x;
        cin>>d>>t>>x;
        d--;

        ans[st.begin()->se]+=t-mae;

        st.erase({-A[d], d});
        A[d]+=x;
        st.insert({-A[d], d});

        mae=t;
    }
    ans[st.begin()->se]+=L-mae;
    int ma=0;
    rep(i,N) chmax(ma, ans[i]);
    rep(i,N) if(ans[i]==ma){
        cout<<i+1<<"\n";
        break;
    }
}
accuracy: 1
time_ms: 280
memory_kb: 8832
final_rank: 8

code_snippet: #include<bits/stdc++.h>
#include <queue>
using namespace std;
#define ll long long
#define rep(i,N) for(ll i=0;i<N;i++)
#define all(x) x.begin(),x.end()

bool solve(){
    ll N,R,L;
    cin>>N>>R>>L;
    vector<ll>S(N,0);
    ll nt = 0,nv = 0;
    vector<ll>time(N,0);
    priority_queue<pair<ll,ll>>Q;
    rep(i,N)Q.push({S[i],-i});
    rep(i,R){
        ll d,t,x;cin>>d>>t>>x;d--;
        time[nv]+=t-nt;
        S[d]+=x;
        Q.push({S[d],-d});
        while(!Q.empty()){
            auto [s,idx] = Q.top();
            if(s!=S[-idx])Q.pop();
            else {
                nv = -idx;
                break;
            }
        }
        nt = t;
        // cout<<nt<<" "<<nv+1<<endl;
    }
    time[nv]+=L-nt;
    ll ans = 0;
    rep(i,N){
        if(time[i]>time[ans])ans = i;
    }
    cout<<ans+1<<endl;
    return false;
}

int main(){
    while(solve());
}
accuracy: 1
time_ms: 280
memory_kb: 22876
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int a[100001],t2[100001];
int main(void)
{
	int n,r,l,i,d,t,x,tt,dd,xx,mx,mi,j;
	P pp;
	priority_queue<P> qu;
	cin >>n>>r>>l;
	tt=0;
	pp.first=0;	pp.second=-1;
	qu.push(pp);
	for(i=0;i<r;i++)	{
//		cout <<"i="<<i<<endl;
		while(1)	{
			pp=qu.top();
			if(pp.first==a[-pp.second])	break;
			qu.pop();
		}
		dd=-pp.second;	
		cin >>d>>t>>x;
		t2[dd]+=t-tt;
		tt=t;
		a[d]+=x;
		pp.first=a[d];	pp.second=-d;
		qu.push(pp);
//		for(j=1;j<=n;j++)	cout <<a[j]<<" ";
//		cout <<endl;
	}
	while(1)	{
		pp=qu.top();
		if(pp.first==a[-pp.second])	break;
		qu.pop();
	}
	dd=-pp.second;	
	t2[dd]+=l-tt;	
	
//	for(j=1;j<=n;j++)	cout <<t2[j]<<" ";
//	cout <<endl;
	
	mx=-1;
	for(i=1;i<=n;i++)	{
		if(mx<t2[i])	{
			mx=t2[i];	mi=i;
		}
	}
	cout <<mi<<endl;
	return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 11576
final_rank: 14

code_snippet: #pragma region Macros

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2")

#include <bits/extc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using namespace __gnu_pbds;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Bdouble = mp::number<mp::cpp_dec_float<256>>;
// Bdouble Beps = 0.00000000000000000000000000000001; // 1e-32
// const bool equals(Bdouble a, Bdouble b) { return mp::fabs(a - b) < Beps; }

#define pb emplace_back
#define int ll
#define endl '\n'
// #define unordered_map<int, int> gp_hash_table<int, int, custom_hash> 

#define sqrt __builtin_sqrtl
#define cbrt __builtin_cbrtl
#define hypot __builtin_hypotl

#define next asdnext
#define prev asdprev

using ll = long long;
using ld = long double;
const ld PI = acosl(-1);
const int INF = 1 << 30;
const ll INFL = 1LL << 61;
// const int MOD = 998244353;
const int MOD = 1000000007;

const ld EPS = 1e-10;
const bool equals(ld a, ld b) { return fabs((a) - (b)) < EPS; }

const vector<int> dx = {0, 1, 0, -1, 1, 1, -1, -1}; // → ↓ ← ↑ ↘ ↙ ↖ ↗
const vector<int> dy = {1, 0, -1, 0, 1, -1, -1, 1};

struct Edge {
    int from, to;
    double cost;
    Edge() : from(-1), to(-1), cost(-1) {}
    Edge(int to, double cost) : to(to), cost(cost) {}
    Edge(int from, int to, double cost) : from(from), to(to), cost(cost) {}
    bool operator ==(const Edge& e) {
        return this->from == e.from && this->to == e.to && this->cost == e.cost;
    }
    bool operator !=(const Edge& e) {
        return this->from != e.from or this->to != e.to or this->cost != e.cost;
    }
};

chrono::system_clock::time_point start;
__attribute__((constructor))
void constructor() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    start = chrono::system_clock::now();
}

random_device seed_gen;
mt19937_64 rng(seed_gen());
uniform_int_distribution<int> dist_x(0, 1e9);
struct RNG {
    unsigned Int(unsigned l, unsigned r) {
        return dist_x(rng) % (r - l + 1) + l;
    }
    ld Double() {
        return ld(dist_x(rng)) / 1e9;
    }
} rnd;

using i64 = ll;
// using i64 = uint64_t;
// bit演算, x==0の場合は例外処理した方がよさそう. 区間は [l, r)
i64 lrmask(i64 l, i64 r) { return (1LL << r) - (1LL << l); }
i64 sub_bit(i64 x, i64 l, i64 r) { i64 b = x & ((1LL << r) - (1LL << l)); return b >> l; } // r溢れ可
i64 bit_width(i64 x) { return 64 - __builtin_clzll(x) + (x == 0); }

i64 popcount(i64 x) { return __builtin_popcountll(x); }
i64 popcount(i64 x, i64 l, i64 r) { return __builtin_popcountll(sub_bit(x, l, r)); }
i64 unpopcount(i64 x) { return bit_width(x) - __builtin_popcountll(x); }
i64 unpopcount(i64 x, i64 l, i64 r) { return r - l - __builtin_popcountll(sub_bit(x, l, r)); }
bool is_pow2(i64 x) { return __builtin_popcountll(x) == 1; }

i64 top_bit(i64 x) { return 63 - __builtin_clzll(x);} // 2^kの位 (x > 0)
i64 bot_bit(i64 x) { return __builtin_ctz(x);} // 2^kの位 (x > 0)
// i64 next_bit(i64 x, i64 k) { return 0; }
// i64 prev_bit(i64 x, i64 k) { return 0; }
// i64 kth_bit(i64 x, i64 k) { return 0; }
i64 MSB(i64 x) { if (x == 0) return 0; return 1LL << (63 - __builtin_clzll(x)); } // mask
i64 LSB(i64 x) { return (x & -x); } // mask

i64 countl_zero(i64 x) { return __builtin_clzll(x); }
i64 countl_one(i64 x) {
    i64 ret = 0, k = 63 - __builtin_clzll(x);
    while (k != -1 && (x & (1LL << k))) { k--; ret++; }
    return ret;
}
i64 countr_zero(i64 x) { return __builtin_ctzll(x); } // x==0のとき64が返ることに注意
i64 countr_one(i64 x) { i64 ret = 0; while (x & 1) { x >>= 1; ret++; } return ret; }

i64 floor_log2(i64 x) { if (x == 0) return 0; return 63 - __builtin_clzll(x); }
i64 bit_floor(i64 x) { if (x == 0) return 0; return 1LL << (63 - __builtin_clzll(x)); } // MSBと同じ
i64 ceil_log2(i64 x) { if (x == 0) return 0; return 64 - __builtin_clzll(x - 1); }
i64 bit_ceil(i64 x) { if (x == 0) return 0; return 1LL << (64 - __builtin_clzll(x - 1)); }

i64 rotl(i64 x, i64 k) { // 有効bit内でrotate. オーバーフロー注意
    i64 w = bit_width(x); k %= w;
    return ((x << k) | (x >> (w - k))) & ((1LL << w) - 1);
}
// i64 rotl(i64 x, i64 l, i64 m, i64 r) {}
i64 rotr(i64 x, i64 k) {
    i64 w = bit_width(x); k %= w;
    return ((x >> k) | (x << (w - k))) & ((1LL << w) - 1);
}
// i64 rotr(i64 x, i64 l, i64 m, i64 r) {}
i64 bit_reverse(i64 x) { // 有効bit内で左右反転
    i64 r = 0, w = bit_width(x);
    for (i64 i = 0; i < w; i++) r |= ((x >> i) & 1) << (w - i - 1);
    return r;
}
// i64 bit_reverse(i64 x, i64 l, i64 r) { return 0; }

bool is_palindrome(i64 x) { return x == bit_reverse(x); }
bool is_palindrome(i64 x, i64 l, i64 r) { i64 b = sub_bit(x, l, r); return b == bit_reverse(b); }
i64 concat(i64 a, i64 b) { return (a << bit_width(b)) | b; } // オーバーフロー注意
i64 erase(i64 x, i64 l, i64 r) { return x>>r<<l | x&(1LL<<l - 1); } // [l, r) をカット

i64 hamming(i64 a, i64 b) { return __builtin_popcountll(a ^ b); }
i64 hamming(i64 a, i64 b, i64 l, i64 r) { return __builtin_popcountll(sub_bit(a, l, r) ^ sub_bit(b, l, r)); }
i64 compcount(i64 x) { return (__builtin_popcountll(x ^ (x >> 1)) + (x & 1)) / 2; }
i64 compcount2(i64 x) { return compcount(x & (x >> 1)); } // 長さ2以上の連結成分の個数
i64 adjacount(i64 x) { return __builtin_popcountll(x & (x >> 1)); } // 隣接する1のペアの個数

i64 next_combination(i64 x) {
    i64 t = x | (x - 1); return (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(x) + 1));
}


__int128_t POW(__int128_t x, int n) {
    __int128_t ret = 1;
    assert(n >= 0);
    if (x == 1 or n == 0) ret = 1;
    else if (x == -1 && n % 2 == 0) ret = 1; 
    else if (x == -1) ret = -1; 
    else if (n % 2 == 0) {
        assert(x < INFL);
        ret = POW(x * x, n / 2);
    } else {
        assert(x < INFL);
        ret = x * POW(x, n - 1);
    }
    return ret;
}
int per(int x, int y) { // x = qy + r (0 <= r < y) を満たすq
    assert(y != 0);
    if (x >= 0 && y > 0) return x / y;
    if (x >= 0 && y < 0) return x / y - (x % y < 0);
    if (x < 0 && y < 0) return x / y + (x % y < 0);
    return x / y - (x % y < 0); //  (x < 0 && y > 0) 
}
int mod(int x, int y) { // x = qy + r (0 <= r < y) を満たすr
    assert(y != 0);
    if (x >= 0) return x % y;
    __int128_t ret = x % y; // (x < 0)
    ret += (__int128_t)abs(y) * INFL;
    ret %= abs(y);
    return ret;
}
int floor(int x, int y) { // (ld)x / y 以下の最大の整数
    assert(y != 0);
    if (y < 0) x = -x, y = -y;
    return x >= 0 ? x / y : (x + 1) / y - 1;
}
int ceil(int x, int y) { // (ld)x / y 以上の最小の整数
    assert(y != 0);
    if (y < 0) x = -x, y = -y;
    return x > 0 ? (x - 1) / y + 1 : x / y;
}
int round(int x, int y) {
    assert(y != 0);
    return (x * 2 + y) / (y * 2);
}
int round(int x, int y, int k) { // (ld)(x/y)を10^kの位に関して四捨五入
    assert(y != 0); // TODO
    return INF;
}
int round2(int x, int y) { // 五捨五超入 // 未verify
    assert(y != 0);
    if (y < 0) y = -y, x = -x;
    int z = z / y;
    if ((z * 2 + 1) * y <= y * 2) z++;
    return z;
}
// int round(ld x, int k) { // xを10^kの位に関して四捨五入
// }
// int floor(ld x, int k) { // xを10^kの位に関してflooring
// }
// int ceil(ld x, int k) { // xを10^kの位に関してceiling
// }
// int kth(int x, int y, int k) { // x / yの10^kの位の桁
// }
int floor(ld x, ld y) { // 誤差対策TODO
    assert(!equals(y, 0));
    return floor(x / y);
    // floor(x) = ceil(x - 1) という話も
}
int ceil(ld x, ld y) { // 誤差対策TODO // ceil(p/q) = -floor(-(p/q))らしい
    assert(!equals(y, 0));
    return ceil(x / y);
    // ceil(x) = floor(x + 1)
}
int perl(ld x, ld y) { // x = qy + r (0 <= r < y, qは整数) を満たす q
    // 未verify. 誤差対策TODO. EPS外してもいいかも。
    assert(!equals(y, 0));
    if (x >= 0 && y > 0) return floor(x / y)+EPS;
    if (x >= 0 && y < 0) return -floor(x / fabs(y));
    if (x < 0 && y < 0) return floor(x / y) + (x - floor(x/y)*y < -EPS);
    return floor(x / y) - (x - floor(x/y)*y < -EPS); //  (x < 0 && y > 0) 
}
ld modl(ld x, ld y) { // x = qy + r (0 <= r < y, qは整数) を満たす r
    // 未verify. 誤差対策TODO. -0.0が返りうる。
    assert(!equals(y, 0));
    if (x >= 0) return x - fabs(y)*fabs(per(x, y));
    return x - fabs(y)*floor(x, fabs(y));
}
int seisuu(ld x) { return (int)x; } // 整数部分. 誤差対策TODO
int modf(ld x) {
	if (x < 0) return ceill(x);
	else return floorl(x);
}
// 正なら+EPS, 負なら-EPSしてから、文字列に直して小数点以下を捨てる?
int seisuu(int x, int y) {
    assert(y != 0);
    return x / y;
}
int seisuu(ld x, ld y) { // 誤差対策TODO
    assert(!equals(y, 0));
    return (int)(x / y);
}

template <class T> pair<T, T> max(const pair<T, T> &a, const pair<T, T> &b) {
    if (a.first > b.first or a.first == b.first && a.second > b.second) return a;
    return b;
}
template <class T> pair<T, T> min(const pair<T, T> &a, const pair<T, T> &b) {
    if (a.first < b.first or a.first == b.first && a.second < b.second) return a;
    return b;
}

template <class T> bool chmax(T &a, const T& b) {
    if (a < b) { a = b; return true; } return false;
}
template <class T> bool chmin(T &a, const T& b) {
    if (a > b) { a = b; return true; } return false;
}
template <class T> T mid(T a, T b, T c) { // 誤差対策TODO
    return a + b + c - max({a, b, c}) - min({a, b, c});
}
template <class T> void Sort(T &a, T &b, bool rev = false) { 
    if (rev == false) {  // TODO テンプレート引数
        if (a > b) swap(a, b);
    } else {
        if (b > a) swap(b, a);
    }
}
template <class T> void sort(T &a, T &b, T &c, bool rev = false) {
    if (rev == false) { 
        if (a > b) swap(a, b); if (a > c) swap(a, c); if (b > c) swap(b, c);
    } else {
        if (c > b) swap(c, b); if (c > a) swap(c, a); if (b > a) swap(b, a);
    }
}
template <class T> void sort(T &a, T &b, T &c, T &d, bool rev = false) {
    if (rev == false) { 
        if (a > b) swap(a, b); if (a > c) swap(a, c);  if (a > d) swap(a, d);
        if (b > c) swap(b, c); if (b > d) swap(b, d); if (c > d) swap(c, d);
    } else {
        if (d > c) swap(d, c); if (d > b) swap(d, b); if (d > a) swap(d, a);
        if (c > b) swap(c, b); if (c > a) swap(c, a); if (b > a) swap(b, a);
    }
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

class Compress {
public:
    int sz = 0;
    // gp_hash_table<int, int, custom_hash> Z, UZ;
    unordered_map<int, int> Z;    // 元の値 -> 圧縮した値
    unordered_map<int, int> UZ;   // 圧縮した値 -> 元の値

    Compress(const vector<int> &V, int base = 0) {
        this->sz = base;
        set<int> s(V.begin(), V.end());

        for (int x : s) {
            this->Z[x] = this->sz;
            this->UZ[this->sz] = x;
            this->sz++;
        }
    }
    
    Compress(const vector<int> &V1, const vector<int> &V2, int base = 0) {
        this->sz = base;
        vector<int> V3 = V2;
        V3.insert(V3.end(), V1.begin(), V1.end());
        set<int> s(V3.begin(), V3.end());

        for (int x : s) {
            this->Z[x] = this->sz;
            this->UZ[this->sz] = x;
            this->sz++;
        }
    }

    Compress(const vector<int> &V1, const vector<int> &V2, const vector<int> &V3, int base = 0) {
        this->sz = base;
        vector<int> V4 = V1;
        V4.insert(V4.end(), V2.begin(), V2.end());
        V4.insert(V4.end(), V3.begin(), V3.end());
        set<int> s(V4.begin(), V4.end());

        for (int x : s) {
            this->Z[x] = this->sz;
            this->UZ[this->sz] = x;
            this->sz++;
        }
    }

    Compress(const vector<int> &V1, const vector<int> &V2,
            const vector<int> &V3, const vector<int> &V4, int base = 0) {
        this->sz = base;
        vector<int> V5 = V1;
        V5.insert(V5.end(), V2.begin(), V2.end());
        V5.insert(V5.end(), V3.begin(), V3.end());
        V5.insert(V5.end(), V4.begin(), V4.end());
        set<int> s(V5.begin(), V5.end());

        for (int x : s) {
            this->Z[x] = this->sz;
            this->UZ[this->sz] = x;
            this->sz++;
        }
    }

    vector<int> zip(const vector<int> &V) {
        vector<int> ret = V;
        for (int i = 0; i < (int)V.size(); i++) {
            ret[i] = Z[ret[i]];
        }
        return ret;
    }

    vector<int> unzip(const vector<int> &V) {
        vector<int> ret = V;
        for (int i = 0; i < (int)V.size(); i++) {
            ret[i] = UZ[ret[i]];
        }
        return ret;
    }

    int size() { return sz; }

    int encode(int x) { return Z[x]; }
    int decode(int x) {
        if (UZ.find(x) == UZ.end()) return -1; // xが元の配列に存在しないとき
        return UZ[x];
    }
};

class UnionFind {
public:
	UnionFind() = default;
    UnionFind(int N) : par(N), sz(N, 1) {
        iota(par.begin(), par.end(), 0);
    }
	int root(int x) {
		if (par[x] == x) return x;
		return (par[x] = root(par[x]));
	}
	bool unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
        if (rx == ry) return false;
		if (sz[rx] < sz[ry]) swap(rx, ry);
		sz[rx] += sz[ry];
		par[ry] = rx;
        return true;
	}
	bool issame(int x, int y) { return (root(x) == root(y)); }
	int size(int x) { return sz[root(x)]; }
    vector<vector<int>> groups(int N) {
        vector<vector<int>> G(N);
        for (int x = 0; x < N; x++) {
            G[root(x)].push_back(x);
        }
		G.erase( remove_if(G.begin(), G.end(),
            [&](const vector<int>& V) { return V.empty(); }), G.end());
        return G;
    }
private:
	vector<int> par, sz;
};

template<typename T>
struct BIT {
    int N;             // 要素数
    vector<T> bit[2];  // データの格納先
    BIT(int N_, int x = 0) {
        N = N_ + 1;
        bit[0].assign(N, 0); bit[1].assign(N, 0);
        if (x != 0) {
            for (int i = 0; i < N; i++) add(i, x);
        }
    }
    BIT(const vector<int> &A) {
        N = A.size() + 1;
        bit[0].assign(N, 0); bit[1].assign(N, 0);
        for (int i = 0; i < (int)A.size(); i++) add(i, A[i]);
    }
    void add_sub(int p, int i, T x) {
        while (i < N) { bit[p][i] += x; i += (i & -i); }
    }
    void add(int l, int r, T x) {
        add_sub(0, l + 1, -x * l); add_sub(0, r + 1, x * r);
        add_sub(1, l + 1, x); add_sub(1, r + 1, -x);
    }
    void add(int i, T x) { add(i, i + 1, x); }
    T sum_sub(int p, int i) {
        T ret = 0;
        while (i > 0) { ret += bit[p][i]; i -= (i & -i); }
        return ret;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
    T sum(int l, int r) { return sum(r) - sum(l); }
    T get(int i) { return sum(i, i + 1); }
    void set(int i, T x) { T s = get(i); add(i, -s + x); }
};

template<int mod> class Modint {
public:
    int val = 0;
    Modint(int x = 0) { while (x < 0) x += mod; val = x % mod; }
    Modint(const Modint &r) { val = r.val; }

    Modint operator -() { return Modint(-val); } // 単項
    Modint operator +(const Modint &r) { return Modint(*this) += r; }
    Modint operator +(const int &q) { Modint r(q); return Modint(*this) += r; }
    Modint operator -(const Modint &r) { return Modint(*this) -= r; }
    Modint operator -(const int &q) { Modint r(q); return Modint(*this) -= r; }
    Modint operator *(const Modint &r) { return Modint(*this) *= r; }
    Modint operator *(const int &q) { Modint r(q); return Modint(*this) *= r; }
    Modint operator /(const Modint &r) { return Modint(*this) /= r; }
    Modint operator /(const int &q) { Modint r(q); return Modint(*this) /= r; }
    
    Modint& operator ++() { val++; if (val >= mod) val -= mod; return *this; } // 前置
    Modint operator ++(signed) { ++*this; return *this; } // 後置
    Modint& operator --() { val--; if (val < 0) val += mod; return *this; }
    Modint operator --(signed) { --*this; return *this; }
    Modint &operator +=(const Modint &r) { val += r.val; if (val >= mod) val -= mod; return *this; }
    Modint &operator +=(const int &q) { Modint r(q); val += r.val; if (val >= mod) val -= mod; return *this; }
    Modint &operator -=(const Modint &r) { if (val < r.val) val += mod; val -= r.val; return *this; }
    Modint &operator -=(const int &q) { Modint r(q);  if (val < r.val) val += mod; val -= r.val; return *this; }
    Modint &operator *=(const Modint &r) { val = val * r.val % mod; return *this; }
    Modint &operator *=(const int &q) { Modint r(q); val = val * r.val % mod; return *this; }
    Modint &operator /=(const Modint &r) {
        int a = r.val, b = mod, u = 1, v = 0;
        while (b) {int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v);}
        val = val * u % mod; if (val < 0) val += mod;
        return *this;
    }
    Modint &operator /=(const int &q) {
        Modint r(q); int a = r.val, b = mod, u = 1, v = 0;
        while (b) {int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v);}
        val = val * u % mod; if (val < 0) val += mod;
        return *this;
    }
    bool operator ==(const Modint& r) { return this -> val == r.val; }
    bool operator <(const Modint& r) { return this -> val < r.val; }
    bool operator >(const Modint& r) { return this -> val > r.val; }
    bool operator !=(const Modint& r) { return this -> val != r.val; }
};

using mint = Modint<MOD>;

istream &operator >>(istream &is, mint& x) {
    int t; is >> t; x = t; return (is);
}
ostream &operator <<(ostream &os, const mint& x) {
    return os << x.val;
}
mint modpow(const mint &x, int n) {
    if (n < 0) return (mint)1 / modpow(x, -n); // 未verify
    assert(n >= 0);
    if (n == 0) return 1;
    mint t = modpow(x, n / 2);
    t = t * t;
    if (n & 1) t = t * x;
    return t;
}

int modpow(__int128_t x, int n, int mod) {
    assert(n >= 0 && mod > 0); // TODO: n <= -1
    __int128_t ret = 1;
    while (n > 0) {
        if (n % 2 == 1) ret = ret * x % mod;
        x = x * x % mod;
        n /= 2;
    }
    return ret;
}
int modinv(__int128_t x, int mod) {
    assert(mod > 0);
    // assert(x > 0);
    if (x == 1 or x == 0) return 1;
    return mod - modinv(mod % x, mod) * (mod / x) % mod;
}

istream &operator >>(istream &is, __int128_t& x) {
    string S; is >> S;
    __int128_t ret = 0;
    int f = 1;
    if (S[0] == '-') f = -1; 
    for (int i = 0; i < S.length(); i++)
        if ('0' <= S[i] && S[i] <= '9')
            ret = ret * 10 + S[i] - '0';
    x = ret * f;
    return (is);
}
ostream &operator <<(ostream &os, __int128_t x) {
    ostream::sentry s(os);
    if (s) {
        __uint128_t tmp = x < 0 ? -x : x;
        char buffer[128]; char *d = end(buffer);
        do {
            --d; *d = "0123456789"[tmp % 10]; tmp /= 10;
        } while (tmp != 0);
        if (x < 0) { --d; *d = '-'; }
        int len = end(buffer) - d;
        if (os.rdbuf()->sputn(d, len) != len) os.setstate(ios_base::badbit);
    }
    return os;
}

__int128_t stoll(string &S) {
    __int128_t ret = 0; int f = 1;
    if (S[0] == '-') f = -1; 
    for (int i = 0; i < S.length(); i++)
        if ('0' <= S[i] && S[i] <= '9') ret = ret * 10 + S[i] - '0';
    return ret * f;
}
__int128_t gcd(__int128_t a, __int128_t b) { return b ? gcd(b, a % b) : a; }
__int128_t lcm(__int128_t a, __int128_t b) {
    return a / gcd(a, b) * b;
    // lcmが__int128_tに収まる必要あり
}

string to_string(ld x, int k) { // xの小数第k位までをstring化する
    assert(k >= 0);
    stringstream ss;
    ss << setprecision(k + 2) << x;
    string s = ss.str();
    if (s.find('.') == string::npos) s += '.';
    int pos = s.find('.');
    for (int i = 0; k >= (int)s.size() - 1 - pos; i++) s += '0';
    s.pop_back();
    if (s.back() == '.') s.pop_back();
    return s;

    // stringstream ss; // 第k+1位を四捨五入して第k位まで返す
    // ss << setprecision(k + 1) << x;
    // string s = ss.str();
    // if (s.find('.') == string::npos) s += '.';
    // int pos = s.find('.');
    // for (int i = 0; k > (int)s.size() - 1 - pos; i++) s += '0';
    // if (s.back() == '.') s.pop_back();
    // return s;
}
string to_string(__int128_t x) {
    string ret = "";
    if (x < 0) { ret += "-"; x *= -1; }
    while (x) { ret += (char)('0' + x % 10); x /= 10; }
    reverse(ret.begin(), ret.end());
    return ret;
}
string to_string(char c) { string s = ""; s += c; return s; }

template<class T> size_t HashCombine(const size_t seed,const T &v) {
    return seed^(hash<T>()(v)+0x9e3779b9+(seed<<6)+(seed>>2));
}
template<class T,class S> struct hash<pair<T,S>>{
    size_t operator()(const pair<T,S> &keyval) const noexcept {
        return HashCombine(hash<T>()(keyval.first), keyval.second);
    }
};
template<class T> struct hash<vector<T>>{
    size_t operator()(const vector<T> &keyval) const noexcept {
        size_t s=0;
        for (auto&& v: keyval) s=HashCombine(s,v);
        return s;
    }
};
template<int N> struct HashTupleCore{
    template<class Tuple> size_t operator()(const Tuple &keyval) const noexcept{
        size_t s=HashTupleCore<N-1>()(keyval);
        return HashCombine(s,get<N-1>(keyval));
    }
};
template <> struct HashTupleCore<0>{
    template<class Tuple> size_t operator()(const Tuple &keyval) const noexcept{ return 0; }
};
template<class... Args> struct hash<tuple<Args...>>{
    size_t operator()(const tuple<Args...> &keyval) const noexcept {
        return HashTupleCore<tuple_size<tuple<Args...>>::value>()(keyval);
    }
};

vector<mint> _fac, _finv, _inv;
void COMinit(int N) {
    _fac.resize(N + 1); _finv.resize(N + 1);  _inv.resize(N + 1);
    _fac[0] = _fac[1] = 1; _finv[0] = _finv[1] = 1; _inv[1] = 1;
    for (int i = 2; i <= N; i++) {
        _fac[i] = _fac[i-1] * mint(i);
        _inv[i] = -_inv[MOD % i] * mint(MOD / i);
        _finv[i] = _finv[i - 1] * _inv[i];
    }
}

mint FAC(int N) {
    if (N < 0) return 0; return _fac[N];
}
mint COM(int N, int K) {
    if (N < K) return 0; if (N < 0 or K < 0) return 0;
    return _fac[N] * _finv[K] * _finv[N - K];
}
mint PERM(int N, int K) {
    if (N < K) return 0; if (N < 0 or K < 0) return 0;
    return _fac[N] *  _finv[N - K];
}
mint NHK(int N, int K) { // initのサイズに注意
    if (N == 0 && K == 0)  return 1;
    return COM(N + K - 1, K);
}

#pragma endregion


unsigned _bit_ceil(unsigned n) {
    unsigned x = 1;
    while (x < (unsigned)(n)) x *= 2;
    return x;
}

int _countr_zero(unsigned n) {
    return __builtin_ctz(n);
}

template <class S, S (*op)(S, S), S (*e)()> struct segtree {
public:
    segtree() : segtree(0) {}
    explicit segtree(int n) : segtree(vector<S>(n, e())) {}
    explicit segtree(const vector<S>& v) : _n(int(v.size())) {
        size = (int)_bit_ceil((unsigned int)(_n));
        log = _countr_zero((unsigned int)size);
        d = vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) const {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    // void add(int p, S x) {
    //     assert(0 <= p && p < _n);
    //     S s = get(p);
    //     set(p, s + x);
    // }

    S prod(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() const { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) const {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) const {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

private:
    int _n, size, log;
    vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};


using S = pair<int, int>;
S op(S x, S y) { return max({x, y}); }
S e() { return make_pair(-INFL, -INFL); }

signed main() {
    int N, Q, L;
    cin >> N >> Q >> L;
    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++) {
        A[i].second = -i;
    }

    segtree<S, op, e> seg(A);

    vector<int> sum(N); // チームiが映った時間の総和
    vector<int> I(Q), T(Q), P(Q);
    for (int i = 0; i < Q; i++) cin >> I[i] >> T[i] >> P[i];
    T.pb(L);
    for (int q = 0; q < Q; q++) {
        int i = I[q], t = T[q], p = P[q];
        i--;

        seg.set(i, make_pair(seg.get(i).first + p, -i));

        pair<int, int> pa = seg.all_prod();
        // cout << pa.second << endl;
        sum[-pa.second] += T[q + 1] - T[q];
        // cout << seg.get(0).first << " " << seg.get(1).first << endl;
    }

    int ma = -INFL, ans = 0;
    for (int i = 0; i < N; i++) {
        if (sum[i] > ma) {
            ma = sum[i];
            ans = i;
        }
    }
    cout << ans + 1 << endl;
}
accuracy: 1
time_ms: 120
memory_kb: 29924
final_rank: 6

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, r, L;
    cin >> n >> r >> L;
    vector<int> d(r + 1), t(r + 1), x(r + 1);
    for (int i = 0; i < r; i++) {
        cin >> d[i] >> t[i] >> x[i];
        d[i] -= 1;
    }
    d[r] = 0, t[r] = L, x[r] = 0;
    vector<int> tm(n);
    vector<int> pt(n);
    set<pair<int, int>> st;
    for (int i = 0; i < n; i++) {
        st.insert({pt[i], -i});
    }
    int pre = 0;
    for (int i = 0; i <= r; i++) {
        auto it = st.rbegin();
        tm[-it->second] += t[i] - pre;
        pre = t[i];

        st.erase({pt[d[i]], -d[i]});
        pt[d[i]] += x[i];
        st.insert({pt[d[i]], -d[i]});
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
        if (tm[res] < tm[i]) res = i;
    }
    cout << res + 1 << endl;
}
accuracy: 1
time_ms: 330
memory_kb: 16004
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;

int n, r, l;
VL scores_by_team;                       // チームごとの得点
VL time_by_team;                         // チームごとの時間
priority_queue<LL, vector<LL>> highest;  // 得点（降順）
map<LL, set<LL>> teams_by_score;         // 得点ごとのチームID
VL elapsed_time = {0};                   // 経過時間
LL top = 1;
VL buf_d, buf_t, buf_x;
LL d, t, x;

void update() {
    for (int j = 0; j < buf_d.size(); ++j) {
        // 旧得点からチームを消去
        teams_by_score[scores_by_team[buf_d[j]]].erase(buf_d[j]);
        // チーム得点を更新
        scores_by_team[buf_d[j]] += buf_x[j];
        // 新たな得点の場合
        if (teams_by_score[scores_by_team[buf_d[j]]].size() == 0)
            highest.push(scores_by_team[buf_d[j]]);
        // 新得点にチームを追加
        teams_by_score[scores_by_team[buf_d[j]]].insert(buf_d[j]);
    }
    // トップチームの時間を更新
    time_by_team[top] += buf_t.back() - elapsed_time.back();
    // 最高点のチームがいなくなったら、最高点を消去
    while (teams_by_score[highest.top()].size() == 0) highest.pop();
    top = *teams_by_score[highest.top()].begin();
    elapsed_time.push_back(buf_t.back());
    buf_d.clear();
    buf_t.clear();
    buf_x.clear();
}
int main() {
    cin >> n >> r >> l;
    scores_by_team.resize(n + 1);
    time_by_team.resize(n + 1);
    for (LL i = 1; i <= n; ++i) teams_by_score[0].insert(i);
    highest.push(0);
    for (int i = 0; i < r; ++i) {
        cin >> d >> t >> x;
        // tが変わったらバッファからデータを取り出し処理
        if (buf_t.size() > 0 && buf_t.back() != t) {
            update();
        }
        buf_d.push_back(d);
        buf_t.push_back(t);
        buf_x.push_back(x);
    }
    if (buf_t.size() > 0) update();
    // 終了時の時間を更新
    time_by_team[top] += l - elapsed_time.back();
    LL team = 1;
    LL max_time = time_by_team[1];
    for (int i = 2; i <= n; ++i) {
        if (time_by_team[i] > max_time) {
            max_time = time_by_team[i];
            team = i;
        }
    }
    cout << team << endl;
    return 0;
}
accuracy: 1
time_ms: 610
memory_kb: 97012
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF INT64_MAX;
priority_queue<pair<int,int> > qu;
queue<pair<int,int > > ck;
int main()
{
    int n,r,l,nt=0,nd=1,nx=0,nw=0;
    cin>>n>>r>>l;
    vector<int> time(n+1,0);
    vector<int> pt(n+1,0);
    vector<int> d(r+1,1),t(r+2,0),x(r+1,0);
    t[r+1]=l;
    for(int i=1;i<=r;i++) cin>>d[i]>>t[i]>>x[i];
    for(int i=0;i<=r;i++){
        if(i==0){
            time[d[i]]+=t[i+1]-nw,nw=t[i+1];
            continue;
        }
        pt[d[i]]+=x[i];
        qu.push({pt[d[i]],d[i]*-1});
        while(pt[qu.top().second*-1]!=qu.top().first) qu.pop();
        time[qu.top().second*-1]+=t[i+1]-nw,nw=t[i+1];
        // while(!qu.empty()){
        //     cout<<qu.top().first<<" "<<qu.top().second<<endl;
        //     cout<<"time="<<time[qu.top().second]<<endl;
        //     ck.push({qu.top().first,qu.top().second});
        //     qu.pop();
        // }
        // while(!ck.empty()){
        //     qu.push({ck.front().first,ck.front().second});
        //     ck.pop();
        // }
        // cout<<endl;
    }
    // for(int i=1;i<=n;i++) cout<<time[i]<<endl;
    // cout<<endl;
    // while(!qu.empty()){
    //     cout<<qu.top().first<<" "<<qu.top().second<<endl;
    //     ck.push({qu.top().first,qu.top().second});
    //     qu.pop();
    // }
    // while(!ck.empty()){
    //     qu.push({ck.front().first,ck.front().second});
    //     ck.pop();
    // }
    int mx=-1000000,ans;
    for(int i=0;i<=n;i++){
        if(mx<time[i]) mx=time[i],ans=i; 
    }
    cout<<ans<<endl;
    return 0;

}
accuracy: 1
time_ms: 360
memory_kb: 19512
final_rank: 16

code_snippet: #include <iostream>
using namespace std;
int max(int *p, int N) {
  int top = 1;
  for (int i = 2; i <= N; i++) {
    if (p[top] < p[i])
      top = i;
  }
  return top;
}
int main() {
  int N, R, L, d, t, x, old = 1, oldt = 0;
  cin >> N >> R >> L;
  int pt[N + 1], ptime[N + 1];
  for (int i = 0; i <= N; i++)
    pt[i] = ptime[i] = 0;
  for (int i = 0; i < R; i++) {
    cin >> d >> t >> x;
    ptime[old] += t - oldt;
    oldt = t;
    pt[d] += x;
    if (x >= 0) {
      if (pt[old] < pt[d])
        old = d;
      if (pt[old] == pt[d] && old > d)
        old = d;
    } else if (old == d)
      old = max(pt, N);
  }
  ptime[old] += L - oldt;
  cout << max(ptime, N) << endl;
  return 0;
}
accuracy: 1
time_ms: 340
memory_kb: 3876
final_rank: 11

code_snippet: #include <iostream>
using namespace std;
int max(long long int *p, int N) {
  int top = 1;
  for (int i = 2; i <= N; i++) {
    if (p[top] < p[i])
      top = i;
  }
  return top;
}
int main() {
  int N, R, L, d, t, x, old = 1, oldt = 0;
  cin >> N >> R >> L;
  long long int pt[N + 1], ptime[N + 1];
  for (int i = 0; i <= N; i++)
    pt[i] = ptime[i] = 0;
  for (int i = 0; i < R; i++) {
    cin >> d >> t >> x;
    ptime[old] += t - oldt;
    oldt = t;
    pt[d] += x;
    if (x >= 0) {
      if (pt[old] < pt[d])
        old = d;
      if (pt[old] == pt[d] && old > d)
        old = d;
    } else {
      if (old == d)
        old = max(pt, N);
    }
  }
  ptime[old] += L - oldt;
  int ans = 1;
  for (int i = 2; i <= N; i++) {
    if (ptime[ans] < ptime[i])
      ans = i;
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 330
memory_kb: 4640
final_rank: 10

code_snippet: #include <climits>
#include <iostream>
#include <utility>
typedef std::pair<int, int> P;
const int MAX_N = 1 << 17;
int n;
P dat[MAX_N * 2 - 1];
int cnt[MAX_N];
void init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2;
  for (int i = 0; i != n * 2 - 1; ++i)
    dat[i] = std::make_pair(INT_MAX, INT_MAX);
  return;
}
void update(int k, P x) {
  k += n - 1;
  dat[k] = x;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = std::min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
  return;
}
P query(int a, int b, int k, int l, int r) {
  if (a >= r || b <= l)
    return std::make_pair(INT_MAX, INT_MAX);
  if (a <= l && r <= b)
    return dat[k];
  else {
    P vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    P vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return std::min(vl, vr);
  }
}
int main() {
  int N, R, L;
  std::cin >> N >> R >> L;
  init(N);
  for (int i = 0; i != N; ++i)
    update(i, std::make_pair(0, i));
  int prevT = 0;
  for (int i = 0; i != R; ++i) {
    int d, t, x;
    std::cin >> d >> t >> x;
    --d;
    if (t != prevT) {
      P p = query(0, N, 0, 0, n);
      cnt[p.second] += t - prevT;
    }
    P p = query(d, d + 1, 0, 0, n);
    update(d, std::make_pair(p.first - x, p.second));
    prevT = t;
  }
  if (prevT != L) {
    P p = query(0, N, 0, 0, n);
    cnt[p.second] += L - prevT;
  }
  int t = -1, id;
  for (int i = 0; i != N; ++i) {
    if (t < cnt[i]) {
      t = cnt[i];
      id = i + 1;
    }
  }
  std::cout << id << std::endl;
  return 0;
}
accuracy: 1
time_ms: 510
memory_kb: 5424
final_rank: 18

code_snippet: #include <algorithm>
#include <cstdio>
#include <utility>
#define rep(i, a) for (int i = 0; i != (a); ++i)
typedef std::pair<int, int> P;
const int MAX_N = 1 << 17, INF = 1 << 30;
int sz;
P dat[2 * MAX_N - 1];
void init(int n) {
  sz = 1;
  while (sz < n)
    sz <<= 1;
  rep(i, 2 * sz - 1) dat[i] = P(INF, INF);
  return;
}
void update(int k, P p) {
  k += sz - 1;
  dat[k] = p;
  while (k > 0) {
    k = (k - 1) >> 1;
    dat[k] = std::min(dat[2 * k + 1], dat[2 * k + 2]);
  }
  return;
}
P query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return P(INF, INF);
  if (a <= l && r <= b)
    return dat[k];
  else
    return std::min(query(a, b, 2 * k + 1, l, (l + r) >> 1),
                    query(a, b, 2 * k + 2, (l + r) >> 1, r));
}
int N, R, L;
int cnt[MAX_N];
int main() {
  scanf("%d%d%d", &N, &R, &L);
  init(N);
  rep(i, N) update(i, P(0, i));
  int prvT = 0;
  rep(i, R) {
    int d, t, x;
    scanf("%d%d%d", &d, &t, &x);
    if (prvT != t)
      cnt[query(0, N, 0, 0, sz).second] += t - prvT;
    --d;
    P p = query(d, d + 1, 0, 0, sz);
    update(d, P(p.first - x, p.second));
    prvT = t;
  }
  if (L != prvT)
    cnt[query(0, N, 0, 0, sz).second] += L - prvT;
  printf("%d\n", std::max_element(cnt, cnt + N) - cnt + 1);
  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 5016
final_rank: 5

code_snippet: #include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP(j, n) for (int j = 0; j < n; j++)
using namespace std;
typedef pair<int, int> P;
int main() {
  int n, r, l;
  cin >> n;
  cin >> r;
  cin >> l;
  int list[n + 1];
  int time[n + 1];
  for (int i = 0; i < n + 1; i++) {
    list[i] = 0;
    time[i] = 0;
  }
  int top = 0;
  int id = 1;
  int nowtime = 0;
  int timemax = 0;
  int timemaxid = 0;
  for (int i = 0; i < r; i++) {
    int d, t, x;
    cin >> d;
    cin >> t;
    cin >> x;
    time[id] += t - nowtime;
    if (time[id] > timemax) {
      timemax = time[id];
      timemaxid = id;
    }
    nowtime = t;
    list[d] += x;
    if (id == d) {
      top += x;
    }
    if (x < 0 && d == id) {
      for (int j = 1; j < n + 1; j++) {
        if (top < list[j] || (top == list[j] && j < id)) {
          top = list[j];
          id = j;
        }
      }
    }
    if (x > 0 && d != id) {
      if (top < list[d] || (top == list[d] && d < id)) {
        top = list[d];
        id = d;
      }
    }
  }
  time[id] += l - nowtime;
  if (time[id] > timemax) {
    timemax = time[id];
    timemaxid = id;
  }
  cout << timemaxid << "\n";
}
accuracy: 1
time_ms: 330
memory_kb: 3872
final_rank: 9

code_snippet: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP(j, n) for (int j = 0; j < n; j++)
using namespace std;
typedef pair<int, int> P;
int lis[100000];
int tim[100000];
int main() {
  int n, r, l;
  scanf("%d %d %d", &n, &r, &l);
  int top = 0;
  int id = 1;
  int nowtime = 0;
  int timemax = 0;
  int timemaxid = 0;
  for (int i = 0; i < r; i++) {
    int d, t, x;
    scanf("%d %d %d", &d, &t, &x);
    tim[id] += t - nowtime;
    if (tim[id] > timemax) {
      timemax = tim[id];
      timemaxid = id;
    }
    nowtime = t;
    lis[d] += x;
    if (id == d) {
      top += x;
    }
    if (x < 0 && d == id) {
      for (int j = 1; j < n + 1; j++) {
        if (top < lis[j] || (top == lis[j] && j < id)) {
          top = lis[j];
          id = j;
        }
      }
    }
    if (x > 0 && d != id) {
      if (top < lis[d] || (top == lis[d] && d < id)) {
        top = lis[d];
        id = d;
      }
    }
  }
  tim[id] += l - nowtime;
  if (tim[id] > timemax) {
    timemax = tim[id];
    timemaxid = id;
  }
  printf("%d\n", timemaxid);
}
accuracy: 1
time_ms: 90
memory_kb: 3860
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
struct team {
  long long n, p, time;
};
bool operator<(const team &t1, const team &t2) {
  if (t1.p == t2.p) {
    return t1.n > t2.n;
  }
  return t1.p < t2.p;
}
priority_queue<team> q;
team tea[100001];
int main() {
  long long n, r, l;
  cin >> n >> r >> l;
  for (int i = 1; i <= n; i++) {
    tea[i].n = i;
    tea[i].p = 0;
    tea[i].time = 0;
    q.push(tea[i]);
  }
  int d, t, x, btime = 0, bnum = 1;
  team tmp;
  for (int i = 0; i < r; i++) {
    cin >> d >> t >> x;
    tea[bnum].time += t - btime;
    tea[d].p += x;
    q.push(tea[d]);
    while (!q.empty()) {
      tmp = q.top();
      if (tmp.p == tea[tmp.n].p) {
        bnum = tmp.n;
        break;
      }
      q.pop();
    }
    btime = t;
  }
  tea[bnum].time += l - btime;
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    ans = tea[i].time > tea[ans].time ? i : ans;
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 29820
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
struct team {
  long long n, p, time;
};
bool operator<(const team &t1, const team &t2) {
  if (t1.p == t2.p) {
    return t1.n > t2.n;
  }
  return t1.p < t2.p;
}
priority_queue<team> q;
team tea[100001];
int main() {
  long long n, r, l;
  cin >> n >> r >> l;
  for (int i = 1; i <= n; i++) {
    tea[i].n = i;
    tea[i].p = 0;
    tea[i].time = 0;
    q.push(tea[i]);
  }
  int d, t, x, btime = 0, bnum = 1;
  team tmp;
  for (int i = 0; i < r; i++) {
    scanf(" %d %d %d", &d, &t, &x);
    tea[bnum].time += t - btime;
    tea[d].p += x;
    q.push(tea[d]);
    while (!q.empty()) {
      tmp = q.top();
      if (tmp.p == tea[tmp.n].p) {
        bnum = tmp.n;
        break;
      }
      q.pop();
    }
    btime = t;
  }
  tea[bnum].time += l - btime;
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    ans = tea[i].time > tea[ans].time ? i : ans;
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 29900
final_rank: 7

code_snippet: #include <cstring>
#include <iostream>
#include <map>
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define INIT(a) memset(a, 0, sizeof(a))
#define fs first
#define sc second
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int v;
P seg[4004000];
void init(int n) {
  v = 1;
  while (v < n)
    v <<= 1;
  rep(i, 2 * v - 1) seg[i] = P(INF, INF);
}
void update(int x, P a) {
  x += v - 1;
  seg[x] = a;
  while (x) {
    x = (x - 1) / 2;
    seg[x] = min(seg[2 * x + 1], seg[2 * x + 2]);
  }
}
P query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return P(INF, INF);
  if (a <= l && r <= b)
    return seg[k];
  P ql = query(a, b, 2 * k + 1, l, (l + r) / 2);
  P qr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(ql, qr);
}
int main() {
  int n, r, l;
  int d, t, x, prv = 0;
  int len[1001000];
  INIT(len);
  cin >> n >> r >> l;
  init(n);
  rep(i, n) update(i, P(0, i));
  rep(i, r) {
    cin >> d >> t >> x;
    P tmp = query(0, n, 0, 0, v);
    len[tmp.sc] += t - prv;
    prv = t;
    update(d - 1, P(seg[d - 1 + v - 1].fs - x, d - 1));
  }
  len[query(0, n, 0, 0, v).sc] += l - prv;
  int ans = 0;
  rep(i, n) {
    if (len[ans] < len[i])
      ans = i;
  }
  cout << ans + 1 << endl;
}
accuracy: 1
time_ms: 430
memory_kb: 38288
final_rank: 19

code_snippet: #include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define INIT(a) memset(a, 0, sizeof(a))
#define fs first
#define sc second
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int v;
P seg[4004000];
inline void init(int n) {
  v = 1;
  while (v < n)
    v <<= 1;
  rep(i, 2 * v - 1) seg[i] = P(INF, INF);
}
inline void update(int x, P a) {
  x += v - 1;
  seg[x] = a;
  while (x) {
    x = (x - 1) >> 1;
    seg[x] = min(seg[2 * x + 1], seg[2 * x + 2]);
  }
}
inline P query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return P(INF, INF);
  if (a <= l && r <= b)
    return seg[k];
  P ql = query(a, b, 2 * k + 1, l, (l + r) / 2);
  P qr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(ql, qr);
}
int n, r, l;
int d, t, x, prv = 0;
int len[1001000];
int main() {
  INIT(len);
  scanf("%d%d%d", &n, &r, &l);
  init(n);
  rep(i, n) update(i, P(0, i));
  rep(i, r) {
    scanf("%d%d%d", &d, &t, &x);
    P tmp = query(0, n, 0, 0, v);
    len[tmp.sc] += t - prv;
    prv = t;
    update(d - 1, P(seg[d - 1 + v - 1].fs - x, d - 1));
  }
  len[query(0, n, 0, 0, v).sc] += l - prv;
  int ans = 0;
  rep(i, n) {
    if (len[ans] < len[i])
      ans = i;
  }
  printf("%d\n", ans + 1);
}
accuracy: 1
time_ms: 190
memory_kb: 38428
final_rank: 12

code_snippet: #include <cstdio>
using namespace std;
int lis[100000];
int tim[100000];
int main() {
  int n, r, l;
  scanf("%d %d %d", &n, &r, &l);
  int top = 0;
  int id = 1;
  int nowtime = 0;
  int timemax = 0;
  int timemaxid = 0;
  for (int i = 0; i < r; i++) {
    int d, t, x;
    scanf("%d %d %d", &d, &t, &x);
    tim[id] += t - nowtime;
    if (tim[id] > timemax) {
      timemax = tim[id];
      timemaxid = id;
    }
    nowtime = t;
    lis[d] += x;
    if (id == d) {
      top += x;
    }
    if (x < 0 && d == id) {
      for (int j = 1; j < n + 1; j++) {
        if (top < lis[j] || (top == lis[j] && j < id)) {
          top = lis[j];
          id = j;
        }
      }
    }
    if (x > 0 && d != id) {
      if (top < lis[d] || (top == lis[d] && d < id)) {
        top = lis[d];
        id = d;
      }
    }
  }
  tim[id] += l - nowtime;
  if (tim[id] > timemax) {
    timemax = tim[id];
    timemaxid = id;
  }
  printf("%d\n", timemaxid);
}
accuracy: 1
time_ms: 90
memory_kb: 3348
final_rank: 1

code_snippet: #include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
int main() {
  int n, r, l, d, t, x, u = 0;
  scanf("%d%d%d", &n, &r, &l);
  int m = 1;
  while (m < n) {
    m <<= 1;
  }
  vector<int> s(n), c(n), p(2 * m - 1, n - 1);
  for (int i = n - 1; i >= 0; --i) {
    p[i + m - 1] = i;
  }
  for (int i = m - 2; i >= 0; --i) {
    p[i] = p[i * 2 + 1];
  }
  for (int i = 0; i < r; ++i) {
    scanf("%d%d%d", &d, &t, &x);
    c[p[0]] += t - u;
    u = t;
    s[d - 1] += x;
    d += m - 2;
    while (d > 0) {
      d = (d - 1) >> 1;
      p[d] = p[2 * d + (s[p[2 * d + 1]] >= s[p[2 * d + 2]] ? 1 : 2)];
    }
  }
  c[p[0]] += l - u;
  int ans = max_element(c.begin(), c.end()) - c.begin() + 1;
  printf("%d\n", ans);
}
accuracy: 1
time_ms: 130
memory_kb: 4224
final_rank: 3