結果

問題 No.1726 [Cherry 3rd Tune B] ジャマイカビアポン
ユーザー hitonanode
提出日時 2021-10-29 22:33:04
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 315 ms / 3,000 ms
コード長 1,511 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 106,996 KB
実行使用メモリ 23,228 KB
最終ジャッジ日時 2024-10-07 12:11:42
合計ジャッジ時間 7,213 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using pint = pair<int, int>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template <typename T> bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }


int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for (auto &x : P) cin >> x;
    vector<pint> AB(N), CD(M);
    for (auto &[x, y] : AB) cin >> x >> y;
    for (auto &[x, y] : CD) cin >> x >> y;

    int ret = 0;

    REP(t, 2) {
        REP(tt, 2) {
            vector<pair<pint, int>> vs;
            REP(i, N) REP(j, M) {
                vs.emplace_back(CD[j] - AB[i], P[i]);
            }
            sort(vs.begin(), vs.end());
            int c = 0;
            REP(k, vs.size()) {
                c += vs[k].second;
                chmax(ret, c);
                if (k + 1 < int(vs.size()) and vs[k].first != vs[k + 1].first) c = 0;
            }

            REP(i, N) AB[i].second *= -1;
        }
        REP(i, N) AB[i].first *= -1;
    }
    cout << ret << '\n';
}
0