Submission #1040391

# Submission time Handle Problem Language Result Execution time Memory
1040391 2024-08-01T03:02:41 Z vjudge1 Divide and conquer (IZhO14_divide) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

main()
{
    long long n;
    cin >> n;
    vector<long long> x(n+1), g(n+1), d(n+1), g1(n+1, 0), d1(n+1, 0);

    for (long long i = 1; i <= n; ++i)
    {
        cin >> x[i] >> g[i] >> d[i];
        g1[i] = g1[i-1] + g[i];
        d1[i] = d1[i-1] + d[i];
    }
    vector <long long> h(n+1);
    for (long long i=1; i<=n; i++) h[i]=-1e15;
    for (long long i=n; i>=1; i--) h[i]=max(h[i+1],d1[i]-x[i]);

    long long res = 0;
    for (long long i=1; i<=n; i++)
    {
        long long l = i, r = n, temp;

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

            if (h[mid] >= d[i - 1] - x[i])
            {
                temp = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }
        res=max(res,g[temp] - g[i - 1]);
    }
    cout << res;
    return 0;
}

Compilation message

divide.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main()
      | ^~~~
divide.cpp: In function 'int main()':
divide.cpp:36:27: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |         res=max(res,g[temp] - g[i - 1]);
      |                           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -