Submission #1323291

#TimeUsernameProblemLanguageResultExecution timeMemory
1323291NgTrung2217Global Warming (CEOI18_glo)C++20
100 / 100
40 ms2396 KiB
#include <bits/stdc++.h>
#define task ""
#define ff first
#define ss second
using namespace std;
using ld = long double;
using ull = unsigned long long;
using ll = long long;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
const char el = '\n';
const char sp = ' ';
const ll inf = 1e18;
const int maxN = 2e5 + 5;

int n, x, a[maxN], l[maxN];

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    if (!(cin >> n >> x)) return 0;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vector <int> v;
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        auto it = lower_bound(v.begin(), v.end(), a[i]);
        l[i] = it - v.begin() + 1;
        ans = max(ans, l[i]);
        if (it != v.end()) *it = a[i];
        else v.push_back(a[i]);
    }
    v.clear();
    for (int i = n; i >= 1; --i)
    {
        int val = -a[i] - x;
        auto it = lower_bound(v.begin(), v.end(), val);
        int xd = lower_bound(v.begin(), v.end(), val + x) - v.begin();
        ans = max(ans, l[i] + xd);
        if (it != v.end()) *it = val;
        else v.push_back(val);
    }
    cout << ans << el;
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...