답안 #198804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198804 2020-01-27T18:24:34 Z Vladikus004 금 캐기 (IZhO14_divide) C++14
0 / 100
10 ms 4344 KB
#include <bits/stdc++.h>
#define inf 2e9
#define ff first
#define ss second
#define all(v) v.begin() , v.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair <ll, int> pii;

const int N = 100000 + 5;

struct obj{
    int x, d, g;
    obj(){
        x = g = d = 0;
    }
};

int n;
ll pref[N], fenw[2 * N], pref_g[N];
obj a[N];

void up(int ind, ll x){
    for (int i = ind; i <= 2 * N; i |= i + 1)
        fenw[i] = min(fenw[i], x);
}

ll get_min(int ind){
    ll ans = inf;
    for (int i = ind; i >= 0; i = (i & (i + 1)) - 1)
        ans = min(ans, fenw[i]);
    return ans;
}

void init(){
    for (int i = 0; i <= 2 * N; i++)
        fenw[i] = inf;
}

map <ll, int> code;

int32_t main()
{
    #ifdef VBH
        freopen("input.txt" , "r" , stdin);
    #endif
        freopen("divide.in" , "r" , stdin);
        freopen("divide.out" , "w" , stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    init();
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].x >> a[i].g >> a[i].d;
    for (int i = 1; i <= n; i++){
        pref_g[i] = a[i].g;
        pref_g[i] += pref_g[i - 1];
        pref[i] = a[i].d;
        pref[i] += pref[i - 1];
    }
    vector <ll> roman;
    for (int i = 1; i <= n; i++){
        roman.push_back(-a[i].x + pref[i]);
        roman.push_back(-a[i].x + pref[i - 1]);
    }
    sort(roman.begin(), roman.end());
    for (int i = 0; i < (int)roman.size(); i++)
        code[roman[i]] = i;
    ll ans = 0;
    for (int i = 1; i <= n; i++){
        ans = max(ans, (ll)a[i].g);
        int ind = code[-a[i].x + pref[i]];
        ll mn = get_min(ind);
        if (mn != inf)
            ans = max(ans, pref_g[i] - pref_g[mn - 1]);
        ind = code[-a[i].x + pref[i - 1]];
        up(ind, i);
    }
    cout << ans;
    return 0;
}

Compilation message

divide.cpp: In function 'int32_t main()':
divide.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("divide.in" , "r" , stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("divide.out" , "w" , stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp: In function 'void init()':
divide.cpp:38:17: warning: iteration 200010 invokes undefined behavior [-Waggressive-loop-optimizations]
         fenw[i] = inf;
                 ^
divide.cpp:37:23: note: within this loop
     for (int i = 0; i <= 2 * N; i++)
                     ~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 4344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 4344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 4344 KB Output isn't correct
2 Halted 0 ms 0 KB -