제출 #571241

#제출 시각아이디문제언어결과실행 시간메모리
571241YouAreMyGalaxyJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
159 ms10084 KiB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 2e5 + 1;
int a[N + 1], b[N + 1], id[N + 1], dp[N + 1], res[N + 1], n;
void read()
{
    cin >> n;
    for (int i = 1; i <= n + 1; ++ i)
    {
        cin >> a[i];
        id[i] = i;
    }
    sort(id + 1, id + n + 2, [&](const int &x, const int &y)
         {
             return a[x] < a[y];
         });
    sort(a + 1, a + n + 2);
    for (int i = 1; i <= n; ++ i)
    {
        cin >> b[i];
    }
    sort(b + 1, b + n + 1);
}
void solve()
{
    for (int i = 1; i <= n; ++ i)
    {
        dp[i] = max(dp[i - 1], max(0, a[i] - b[i]));
    }
    for (int i = n + 1, k = 0; i >= 1; -- i)
    {
        res[id[i]] = max(dp[i - 1], k);
        k = max(k, max(0, a[i] - b[i - 1]));
    }
    for (int i = 1; i <= n + 1; ++ i)
    {
        cout << res[i] << ' ';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

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