Submission #625255

#TimeUsernameProblemLanguageResultExecution timeMemory
625255boris_mihovJust Long Neckties (JOI20_ho_t1)C++14
Compilation error
0 ms0 KiB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 200000 + 10;
const llong INF = 1e18;

int n;
int a[MAXN];
int b[MAXN];
int idx[MAXN];
int output[MAXN];
int prefix[MAXN];
int suffix[MAXN];

void solve()
{
    std::iota(idx + 1, idx + 1 + n, [&](int x, int y)
    {
        return a[x] < a[y];
    });

    std::sort(a + 1, a + 2 + n);
    std::sort(b + 1, b + 1 + n);
    
    for (int i = 1 ; i <= n ; ++i)
    {
        prefix[i] = std::max(prefix[i - 1], a[i] - b[i]);
    }

    for (int i = n ; i >= 1 ; --i)
    {
        suffix[i] = std::max(suffix[i + 1], a[i+1] - b[i]);
    }

    for (int i = 1 ; i <= n + 1 ; ++i)
    {
        ans[idx[i]] = std::max(prefix[i - 1], suffix[i]);
    }

    for (int i = 1 ; i <= n + 1 ; ++i)
    {
        std::cout << output[i] << ' ';
    }

    std::cout << '\n';
}

void read()
{
    std::cin >> n;
    for (int i = 1 ; i <= n + 1 ; ++i) std::cin >> a[i];
    for (int i = 1 ; i <= n ; ++i) std::cin >> b[i];
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}

Compilation message (stderr)

ho_t1.cpp: In function 'void solve()':
ho_t1.cpp:40:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   40 |         ans[idx[i]] = std::max(prefix[i - 1], suffix[i]);
      |         ^~~
      |         abs
In file included from /usr/include/c++/10/numeric:62,
                 from ho_t1.cpp:3:
/usr/include/c++/10/bits/stl_numeric.h: In instantiation of 'void std::iota(_ForwardIterator, _ForwardIterator, _Tp) [with _ForwardIterator = int*; _Tp = solve()::<lambda(int, int)>]':
ho_t1.cpp:23:6:   required from here
/usr/include/c++/10/bits/stl_numeric.h:99:15: error: cannot convert 'solve()::<lambda(int, int)>' to 'int' in assignment
   99 |    *__first = __value;
      |               ^~~~~~~
      |               |
      |               solve()::<lambda(int, int)>
/usr/include/c++/10/bits/stl_numeric.h:100:4: error: no match for 'operator++' (operand type is 'solve()::<lambda(int, int)>')
  100 |    ++__value;
      |    ^~~~~~~~~