답안 #1052008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052008 2024-08-10T11:02:35 Z vjudge1 금 캐기 (IZhO14_divide) C++17
100 / 100
154 ms 6748 KB
#include <bits/stdc++.h>
using namespace std;

#define SPEED ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define pb push_back
#define pf push_front
#define nl "\n"
#define ll long long
#define int long long
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
#define len(a) a.size()
#define pii pair<int,int>
const int N = 100000 + 4;
const ll md = 998244353;
const ll mod = 1e9 + 7;
const ll mega = 1e6 + 3;
const ll inf = 100100;
int x[N] , g[N] , d[N] , pref[N] , pref2[N] ,n , ans , mx;
void add(int l){
    ans += d[l];
}
void del(int l){
    ans -= d[l];
}
void solve() {
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> x[i] >> g[i] >> d[i];
        pref[i] = pref[i - 1] + d[i];
        pref2[i] = pref2[i - 1] + g[i];
    }
    int mx = 0;
    if(n <= 5000){
        for(int i = 1; i <= n; ++i){
            for(int j = i; j <= n; ++j){
                if(x[j] - x[i] <= pref[j] - pref[i - 1]){
                    mx = max(mx , pref2[j] - pref2[i - 1]);
                }
            }
        }
        cout << mx;
    }
    else{
        for(int i = 1; i <= n; ++i){
            for(int j = i; j <= min(n , i + 1000); ++j){
                if(x[j] - x[i] <= pref[j] - pref[i - 1]){
                    mx = max(mx , pref2[j] - pref2[i - 1]);
                }
            }
            for(int j = n; j >= max(i , n - 1000); --j){
                if(x[j] - x[i] <= pref[j] - pref[i - 1]){
                    mx = max(mx , pref2[j] - pref2[i - 1]);
                }
            }
        }
        cout << mx;
    }
}
signed main() {
    SPEED;
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    // #ifndef ONLINE_JUDGE
    // cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    // #endif
    // return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2560 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 2576 KB Output is correct
23 Correct 8 ms 2644 KB Output is correct
24 Correct 8 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2560 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 2576 KB Output is correct
23 Correct 8 ms 2644 KB Output is correct
24 Correct 8 ms 2396 KB Output is correct
25 Correct 10 ms 2648 KB Output is correct
26 Correct 14 ms 2652 KB Output is correct
27 Correct 14 ms 2544 KB Output is correct
28 Correct 73 ms 3464 KB Output is correct
29 Correct 85 ms 3420 KB Output is correct
30 Correct 154 ms 4436 KB Output is correct
31 Correct 142 ms 4188 KB Output is correct
32 Correct 147 ms 4188 KB Output is correct
33 Correct 147 ms 4348 KB Output is correct
34 Correct 141 ms 4188 KB Output is correct
35 Correct 133 ms 6488 KB Output is correct
36 Correct 125 ms 6748 KB Output is correct