Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- int n, a;
- int w[1 << 11], x[1 << 11], v[1 << 11];
- struct frac {
- int x, y;
- bool operator<(const frac &f) const
- {
- // this->x/this->y < f.x/f.y for y > 0
- assert(y > 0);
- assert(f.y > 0);
- return this->x * f.y < this->y * f.x;
- }
- };
- using pfi = pair<frac, int>;
- int main(int argc, char **argv)
- {
- cin >> n >> a;
- for (int i = 1; i <= n; ++i)
- cin >> w[i] >> x[i] >> v[i];
- int ans = 0;
- frac zero{0, 1};
- for (int i = 1; i <= n; ++i) {
- vector<pfi> vec;
- for (int j = 1; j <= n; ++j) {
- int dv = v[j] - v[i];
- int dx = x[j] - x[i];
- if (dv == 0) {
- if (dx >= 0 && dx <= a)
- vec.push_back({zero, w[j]});
- } else if (dv > 0) {
- vec.push_back({{-dx, dv}, w[j]});
- vec.push_back({{a - dx, dv}, -w[j]});
- } else {
- vec.push_back({{dx - a, -dv}, w[j]});
- vec.push_back({{dx, -dv}, -w[j]});
- }
- }
- sort(vec.begin(), vec.end());
- int acc = 0;
- for (const auto &[f, w] : vec) {
- acc += w;
- fprintf(stderr, "f:%d,%d w:%d\n", f.x, f.y, w);
- if (!(f < zero))
- ans = max(ans, acc);
- }
- fprintf(stderr, "\n\n");
- }
- printf("%d\n", ans);
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement