結果

問題 No.723 2つの数の和
ユーザー DaYuanChi
提出日時 2021-01-30 15:01:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 440 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 171,408 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-28 02:38:31
合計ジャッジ時間 3,092 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  int n, x; cin >> n >> x;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  ll ans = 0;
  for(int i = 0; i < n; i++){
    int num = x - a[i];
    if(num < 0) break;
    ans += upper_bound(a.begin(), a.end(), num)
                - lower_bound(a.begin(), a.end(), num);
  }
  cout << ans << endl;
  return 0;
}
      
0