#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
ll inf = 1e18;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    bool ok = 1;
    for (int i = 0; i < n; i++) {
        if (x[i] > 1) {
            ok = 0;
        }
    }
    if (ok) {
        vector<pair<int, int>> y0, y1;
        for (int i = 0; i < m; i++) {
            if (x[i] == 0) {
                y0.push_back({y[i], w[i]});
            } else {
                y1.push_back({y[i], w[i]});
            }
        }
        sort(y0.begin(), y0.end());
        sort(y1.begin(), y1.end());
        vector<ll> cnt0(n), cnt1(n);
        for (int i = 0; i < y0.size(); i++) {
            cnt0[y0[i].fi] += y0[i].se;
        }
        for (int i = 0; i < y1.size(); i++) {
            cnt1[y1[i].fi] += y1[i].se;
        }
        for (int i = 1; i < n; i++) {
            cnt0[i] += cnt0[i - 1];
            cnt1[i] += cnt1[i - 1];
        }
        ll res = max(cnt1[n - 1], cnt0[n - 1]);
        if (n == 2) {
            return res;
        }
        for (int i = 0; i < n; i++) {
            res = max(res, cnt0[i] + cnt1[n - 1] - cnt1[i]);
        }
        return res;
    }
    ll res = 0;
    for (int i = 0; i < m; i++) {
        res += w[i];
    }
    return res;
}
/*
signed main() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m), y(m), w(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i] >> w[i];
    }
    cout << max_weights(n,m,x,y,w) << '\n';
}
 */
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |