結果

問題 No.2859 Falling Balls
ユーザー t98slider
提出日時 2024-08-27 01:29:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 159 ms / 3,000 ms
コード長 1,096 bytes
コンパイル時間 4,399 ms
コンパイル使用メモリ 264,596 KB
最終ジャッジ日時 2025-02-24 02:21:57
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

// これに似てた
// https://yukicoder.me/problems/no/1826
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

ll op(ll lhs, ll rhs){
	return max(lhs, rhs);
}
constexpr ll e(){
	return -(1ll << 62);
}

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
	for(T& x : vec) is >> x;
	return is;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	ll k;
	cin >> n >> k;
	vector<int> x(n), t(n), c(n);
	vector<tuple<ll,ll,int>> a(n);
	vector<ll> ca(n + 1);
	cin >> t >> x >> c;
	for(int i = 0; i < n; i++){
		a[i] = make_tuple(x[i] + k * t[i], -(x[i] - k * t[i]), c[i]);
		ca[i] = get<1>(a[i]);
	}
	sort(a.begin(), a.end());
	sort(ca.begin(), ca.end());
	ca.erase(unique(ca.begin(), ca.end()), ca.end());
	const int m = ca.size();
	atcoder::segtree<ll, op, e> seg(m);
	auto pget = [&](ll pos){ return lower_bound(ca.begin(), ca.end(), pos) - ca.begin(); };
	seg.set(pget(0), 0);
	for(auto &&[u, v, c] : a){
		if(u < 0) continue;
		int p = pget(v);
		seg.set(p, seg.prod(0, p + 1) + c);
	}
	cout << seg.all_prod() << '\n';
}
0