Submission #1144711

#TimeUsernameProblemLanguageResultExecution timeMemory
1144711minggaJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
64 ms11592 KiB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 2e5 + 7;
int n;
pair<int, int> a[N];
int b[N], ans[N], mx_lef[N], mx_rig[N];

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n;
	for(int i = 1; i <= n + 1; i++) cin >> a[i].fi, a[i].se = i;
	for(int i = 1; i <= n; i++) cin >> b[i];
	sort(a + 1, a + n + 2);
	sort(b + 1, b + n + 1);

	for(int i = 1; i <= n + 1; i++) {
		mx_lef[i] = max(mx_lef[i - 1], (a[i].fi - b[i]));
	}
	for(int i = n; i > 0; i--) {
		mx_rig[i] = max(mx_rig[i + 1], a[i + 1].fi - b[i]);
	}
	for(int i = 1; i <= n + 1; i++) {
		ans[a[i].se] = max(mx_lef[i - 1], mx_rig[i]); 
	}
	for(int i = 1; i <= n + 1; i++) cout << ans[i] << ' ';
  cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

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