Submission #1040374

#TimeUsernameProblemLanguageResultExecution timeMemory
1040374vjudge1Divide and conquer (IZhO14_divide)C++17
100 / 100
18 ms6504 KiB
#include <bits/stdc++.h>
using namespace std;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define fo(i, a, b) for (int i = a; i >= b; i--)
#define minimize(a, b) a = (a < b ? a : b)
#define maximize(a, b) a = (a > b ? a : b) 
#define int long long
#define fi first
#define se second
#define ll long long
#define pii pair <int, int>
#define pb push_back
#define pi acos(-1)
#define sz(a) (int)a.size()
#define getbit(a, b) (((a) >> (b)) & 1)
#define INOUT "main"
#define INFT 0x3f3f3f3f
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cout << *it << " = [" << a << "]" << '\n';
    err(++it, args...);
}
#define debug1(a, st, en) { cout << #a << " = ["; int kt = false; f(i, st, en) {if (kt) cout << ", "; kt = true; cout << a[i];} cout << "]\n"; } 

void ctime()
{
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

void file()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    if (fopen(INOUT".INP", "r")) 
    {
        freopen(INOUT".INP", "r", stdin); 
        freopen(INOUT".OUT", "w", stdout);
    }
}

const int MX_N = 1e5 + 5;
int n;
int x[MX_N], g[MX_N], e[MX_N], mx[MX_N];

signed main()
{
    file();

    cin >> n;
    f(i, 1, n) 
    {
        cin >> x[i] >> g[i] >> e[i];

        g[i] += g[i - 1];
        e[i] += e[i - 1];
    }

    f(i, 1, n + 1) mx[i] = -1e15;
    fo(i, n, 1) mx[i] = max(mx[i + 1], e[i] - x[i]);

    ll res = 0;

    f(i, 1, n)
    {
        int l = i, r = n, ans;

        while(l <= r)
        {
            int mid = (l + r) / 2;

            if (mx[mid] >= e[i - 1] - x[i])
            {
                ans = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }

        maximize(res, g[ans] - g[i - 1]);
    }

    cout << res;

    ctime();
    return 0;
}

Compilation message (stderr)

divide.cpp: In function 'void file()':
divide.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(INOUT".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(INOUT".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp: In function 'int main()':
divide.cpp:83:28: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   83 |         maximize(res, g[ans] - g[i - 1]);
      |                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...