답안 #332208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332208 2020-12-01T16:52:59 Z topovik 금 캐기 (IZhO14_divide) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define INF 1000000000

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<
ll,
null_type,
greater<ll>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

const ll N = 2e5;

ll a[N], b[N], c[N];

ll ans = 0;
ll n;

void Divide(ll l, ll r)
{
    if (l == r)
    {
        ans = max(ans, b[l]);
        return;
    }
    ll mdl = (l + r) >> 1;
    Divide(l, mdl);
    Divide(mdl + 1, r);
    vector <pair<ll, ll> > fr, sc;
    ll power = 0, sum = 0;
    for (ll i = mdl + 1; i <= r; i++) sum += b[i], power += c[i] - (a[i] - a[i - 1]), sc.pb({power, sum});
    power = 0, sum = 0;
    for (ll i = mdl; i >= l; i--) power += c[i] - (a[min(i + 1, mdl)] - a[i]), sum += b[i], fr.pb({power, sum});
    sort(fr.begin(), fr.end());
    sort(sc.begin(), sc.end());
    ll j = sc.size() - 1, mx = -1e9;
    for (ll i = 0; i < fr.size(); i++)
    {
        while (j >= 0 && sc[j].f + fr[i].f >= 0) mx = max(mx, sc[j].s), j--;
        ans = max(ans, fr[i].s + mx);
    }
}

int main()
{
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    Divide(0, n - 1);
    cout << ans;
}

Compilation message

divide.cpp: In function 'void Divide(ll, ll)':
divide.cpp:47:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (ll i = 0; i < fr.size(); i++)
      |                    ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -