답안 #1113239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113239 2024-11-16T07:31:31 Z 0pt1mus23 금 캐기 (IZhO14_divide) C++14
100 / 100
29 ms 10064 KB
// el psy congroo
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert      
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return; 
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 2e5 +23, inf = LLONG_MAX, LG = 20;

int T[sze*4];
int pref[sze];
int gold[sze];
int pos[sze];

void build(int node,int l,int r){
    if(l==r){
        T[node]=pref[l-1]-pos[l];
        return;
    }
    int mid = (l+r)/2;
    build(2*node,l,mid);
    build(2*node +1,mid+1,r);
    T[node]=min(T[node*2],T[node *2 +1]);
}
int qry(int node,int l,int r,int lazim){
    if(l==r){
        return (T[node]<=lazim ? l:0);
    }
    int mid = (l+r)/2;
    if(T[2*node] <= lazim){
        return qry(2*node,l,mid,lazim);
    }
    return qry(2*node +1,mid+1,r,lazim);
}

void fast(){
    int n;
    cin>>n;
    vector<array<int,3>> arr(n+1);
    for(int i=1;i<=n;i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
        pos[i]=arr[i][0];
        pref[i]=pref[i-1]+arr[i][2];
        gold[i]=gold[i-1]+arr[i][1];
    }
    build(1,1,n);
    int ans=0;
    for(int i=1;i<=n;i++){
        int r=  qry(1,1,n,pref[i]-arr[i][0]);
        if(r){
            ans=max(ans, gold[i]-gold[r-1]);
        }
    }
    putr(ans);
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int tt = 1;
    // cin>>tt;
 
    while(tt--){
        fast();
    }
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 1 ms 400 KB Output is correct
23 Correct 3 ms 848 KB Output is correct
24 Correct 3 ms 820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 1 ms 400 KB Output is correct
23 Correct 3 ms 848 KB Output is correct
24 Correct 3 ms 820 KB Output is correct
25 Correct 2 ms 848 KB Output is correct
26 Correct 4 ms 1240 KB Output is correct
27 Correct 3 ms 1360 KB Output is correct
28 Correct 12 ms 4828 KB Output is correct
29 Correct 14 ms 4944 KB Output is correct
30 Correct 29 ms 10064 KB Output is correct
31 Correct 22 ms 8924 KB Output is correct
32 Correct 22 ms 9040 KB Output is correct
33 Correct 21 ms 8624 KB Output is correct
34 Correct 23 ms 8784 KB Output is correct
35 Correct 26 ms 9296 KB Output is correct
36 Correct 27 ms 9364 KB Output is correct