Submission #1234539

#TimeUsernameProblemLanguageResultExecution timeMemory
1234539Bui_Quoc_CuongJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
62 ms8620 KiB
#include <bits/stdc++.h>
#define ll long long
#define FOR(i, a, b) for(int i = a; i <= (int)b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int)b; i--)
#define ALL(A) A.begin(), A.end()
using namespace std;
const int maxn = 200005;
int n;
int c[maxn], a[maxn];
pair <int, int> b[maxn];
int id[maxn], ans[maxn], mx[maxn], pre[maxn];
int main(){
    cin.tie(nullptr) -> sync_with_stdio(false);
    #define taskname "kieuoanh"
    if(fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout);
    }
    cin >> n;
    FOR(i, 1, n + 1) cin >> c[i];
    FOR(i, 1, n) cin >> a[i];
    sort(a + 1, a + 1 + n);

    // if(n <= 2000){
	//     FOR(i, 1, n + 1){
	//     	int ans = 0;
	//     	vector <int> cur;
	//     	FOR(j, 1, n + 1) if(i != j) cur.push_back(c[j]);
	//     	sort(ALL(cur));
	//     	FOR(j, 1, n) ans = max(ans, max(0, cur[j - 1] - a[j]));
	//     	cout << ans << " ";
	//     }
	//     return 0;
	// }

    FOR(i, 1, n + 1) b[i] = make_pair(c[i], i);
    sort(b + 1, b + 1 + n + 1);
    FOR(i, 1, n + 1) id[b[i].second] = i;
	
	FORD(i, n, 1) mx[i] = max(mx[i + 1], max(0, b[i + 1].first - a[i]));
	FOR(i, 1, n) pre[i] = max(pre[i - 1], max(0, b[i].first - a[i]));

	FOR(i, 1, n + 1){
		int pos = id[i];
		ans[i] = max(pre[pos - 1], mx[pos]);
	}
	FOR(i, 1, n + 1) cout << ans[i] << " ";

    return 0;
}

Compilation message (stderr)

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