結果
| 問題 |
No.2859 Falling Balls
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-08-25 15:32:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,753 bytes |
| コンパイル時間 | 4,254 ms |
| コンパイル使用メモリ | 265,692 KB |
| 最終ジャッジ日時 | 2025-02-24 01:28:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 20 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;
ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}
template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}
template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}
// Coodinate Compression
// https://youtu.be/fR3W5IcBGLQ?t=8550
template<typename T=int>
struct CC {
bool initialized;
vector<T> xs;
CC(): initialized(false) {}
void add(T x) { xs.push_back(x);}
void init() {
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(),xs.end()),xs.end());
initialized = true;
}
int operator()(T x) {
if (!initialized) init();
return upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1;
}
T operator[](int i) {
if (!initialized) init();
return xs[i];
}
int size() {
if (!initialized) init();
return xs.size();
}
};
const long long INF = 1001001001001001001;
using S = long long;
S op(S a, S b){
return max(a, b);
}
S e(){
return -INF;
}
int main(){
int n;
long long k;
cin >> n >> k;
vector<long long> t(n);
vector<long long> x(n);
vector<long long> c(n);
cin >> t >> x >> c;
t.push_back(0);
x.push_back(0);
c.push_back(0);
vector<long long> ktpx;
vector<long long> ktmx;
rep(i, n + 1) ktpx.push_back(k * t[i] + x[i]);
rep(i, n + 1) ktmx.push_back(k * t[i] - x[i]);
CC<long long> cc;
rep(i, n + 1) cc.add(ktmx[i]);
int m = cc.size();
segtree<S, op, e> seg(m);
map<int, vector<int>> event;
rep(i, n + 1) event[ktpx[i]].push_back(i);
for(auto& [z, vec] : event){
sort(vec.begin(), vec.end(), [&](int i, int j){return ktmx[i] < ktmx[j];});
for(int i : vec){
if(i == n){
seg.set(cc(0), 0);
}else{
int idx = cc(ktmx[i]);
auto val = seg.prod(0, idx + 1);
if(val != -INF) seg.set(idx, val + c[i]);
}
}
// cout << seg;
}
long long ans = seg.all_prod();
cout << ans << "\n";
return 0;
}