답안 #290503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290503 2020-09-03T22:45:11 Z eggag32 Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
0 ms 384 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int n, l;

int solve(vector<pi> x){
	int ret = 0, cnt = 0;
	multiset<int> st;
	rep(i, n) if(x[i].fi <= x[i].se){
		//we keep the changes and all
		st.insert(x[i].se - x[i].fi);
		cnt++;
	}
	ret = max(ret, cnt); //equivalent to a full sweep in one direction
	int prev = l;
	int tot = 0;
	for(int i = n - 1; i >= 0; i--){
		//we 'extend' to stamp i
		tot += prev - x[i].fi;
		if((l - x[i].fi) <= x[i].se) cnt++;
		if(x[i].se >= x[i].fi){ //it is already counted, but we cant sub twice
			cnt--;
			auto it = st.find(x[i].se - x[i].fi);
			if(it != st.end()) st.erase(it);
		}
		while(st.size() && *st.begin() < (tot * 2)){
			cnt--;
			st.erase(st.begin());
		}
		prev = x[i].fi;
		ret = max(ret, cnt);
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	cin >> n >> l;
	vector<pi> x(n);
	rep(i, n) cin >> x[i].fi;
	rep(i, n) cin >> x[i].se;
	int mx = solve(x);
	rep(i, n) x[i].fi = l - x[i].fi;
	sort(all(x));
	mx = max(mx, solve(x));
	cout << mx << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -