Submission #364606

#TimeUsernameProblemLanguageResultExecution timeMemory
364606Killer2501Just Long Neckties (JOI20_ho_t1)C++14
100 / 100
138 ms19180 KiB
#include <bits/stdc++.h>
#define pb push_back
#define task "sequence"
#define pll pair<ll, ll>
#define pii pair<vector<ll>, ll>
#define fi first
#define se second

using ll = long long;
const long long mod = 1e15+7;
const ll mod1 = 1e9+1;
const ll N = 2e5+5;
const int base = 350;
using ull = unsigned long long;
using namespace std;
string s, ss;
ll n, m, t, k, T, cnt, tong, a[N], c[N], b[N], l[N], r[N], d[N];
vector<ll> adj[N], kq;
pll p[N];
bool cmp(const ll& x, const ll& y)
{
    return a[x] < a[y];
}
void sol()
{
    cin >> n;
    for(int i = 1; i <= n+1; i ++)cin >> a[i], c[i] = i;
    for(int i = 1; i <= n; i ++)cin >> b[i];
    sort(b+1, b+1+n);
    sort(c+1, c+1+n+1, cmp);
    for(int i = 1; i <= n; i ++)
    {
        //cout << a[c[i]] <<" "<<b[i]<<'\n';
        d[c[i]] = i;
        l[i] = max(l[i-1], a[c[i]] - b[i]);
    }
    for(int i = n+1; i > 1; i --)
    {
        r[i] = max(r[i+1], a[c[i]] - b[i-1]);
        d[c[i]] = i;
    }
    //for(int i = 1; i <= n+1; i ++)cout << d[i] <<" ";
    for(int i = 1; i <= n+1; i ++)cout << max(l[d[i]-1], r[d[i]+1])<<" ";
}

int main()
{
    if(fopen(task".in", "r")){
       freopen(task".in", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest;
    ntest =  1;
    //cin >> ntest;
    //cout << (1<<30) << '\n';
    while(ntest -- > 0)
    sol();

}

Compilation message (stderr)

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