Submission #337162

#TimeUsernameProblemLanguageResultExecution timeMemory
337162ryanseeJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
300 ms21868 KiB
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
ll n,B[MAXN],ans[MAXN];
pi A[MAXN];
int main(){
	FAST
	cin>>n;
	FOR(i,1,n+1)cin>>A[i].f,A[i].s=i;
	FOR(i,1,n)cin>>B[i];
	sort(B+1,B+n+1), sort(A+1,A+n+2);
	ll p_mx=-LLINF;
	multiset<ll> ms;
	ms.ins(-LLINF);
	FOR(i,1,n)ms.ins(A[i+1].f-B[i]);
	ans[A[1].s]=*--ms.end();
	FOR(i,2,n+1){
		ms.erase(ms.find(A[i].f-B[i-1]));
		p_mx=max(p_mx,(A[i-1].f-B[i-1]));
		ans[A[i].s]=max(p_mx,*--ms.end());
	}
	FOR(i,1,n+1)cout<<max(0ll,ans[i])<<' ';cout<<'\n';
}

Compilation message (stderr)

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:22:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   22 | #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
      |                    ^~~
ho_t1.cpp:47:2: note: in expansion of macro 'FOR'
   47 |  FOR(i,1,n+1)cout<<max(0ll,ans[i])<<' ';cout<<'\n';
      |  ^~~
ho_t1.cpp:47:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   47 |  FOR(i,1,n+1)cout<<max(0ll,ans[i])<<' ';cout<<'\n';
      |                                         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...