結果

問題 No.728 ギブ and テイク
コンテスト
ユーザー 梧桐
提出日時 2026-01-27 03:19:11
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 1,080 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,112 ms
コンパイル使用メモリ 107,236 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-27 03:19:15
合計ジャッジ時間 4,083 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
typedef long long LL;
 
const int N = 30010;
 
struct House {
    int x, l, r;
};
 
LL ans;
House h[N];
int n, a[N];
set<int> s[N];
map<int, int> mm;
 
int main() {
    freopen("candy.in", "r", stdin);
    freopen("candy.out", "w", stdout);
 
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        h[i].x = a[i];
        mm[a[i]] = i;
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &h[i].l, &h[i].r);
        h[i].l = h[i].x - h[i].l, h[i].r = h[i].x + h[i].r;
    }
 
    sort(a + 1, a + n + 1);
 
    for (int i = 1; i <= n; ++i) {
        for (int j = lower_bound(a + 1, a + n + 1, h[i].l) - a; j <= upper_bound(a + 1, a + n + 1, h[i].r) - a - 1; ++j) {
            if (i == j) continue;
            s[mm[a[j]]].insert(i);
        }
    }
 
    for (int i = 1; i <= n; ++i) {
        for (auto e : s[i]) {
            if (s[e].count(i)) ++ans;
        }
    }
 
    printf("%lld\n", ans / 2);
 
    return 0;
}
0