Submission #571241

# Submission time Handle Problem Language Result Execution time Memory
571241 2022-06-01T15:22:28 Z YouAreMyGalaxy Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
159 ms 10084 KB
//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();
    }
}

Compilation message

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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 388 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 388 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 126 ms 9192 KB Output is correct
34 Correct 126 ms 9684 KB Output is correct
35 Correct 125 ms 9292 KB Output is correct
36 Correct 144 ms 9756 KB Output is correct
37 Correct 144 ms 10084 KB Output is correct
38 Correct 142 ms 9916 KB Output is correct
39 Correct 153 ms 8976 KB Output is correct
40 Correct 145 ms 9008 KB Output is correct
41 Correct 126 ms 9000 KB Output is correct
42 Correct 142 ms 9020 KB Output is correct
43 Correct 141 ms 8888 KB Output is correct
44 Correct 141 ms 8536 KB Output is correct
45 Correct 145 ms 8648 KB Output is correct
46 Correct 147 ms 8544 KB Output is correct
47 Correct 96 ms 8588 KB Output is correct
48 Correct 91 ms 8672 KB Output is correct
49 Correct 149 ms 9212 KB Output is correct
50 Correct 145 ms 9232 KB Output is correct
51 Correct 159 ms 9176 KB Output is correct
52 Correct 152 ms 9236 KB Output is correct
53 Correct 149 ms 9232 KB Output is correct