結果

問題 No.1890 Many Sequences Sum Queries
ユーザー tnakao0123
提出日時 2022-04-04 20:23:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 42,564 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-25 13:21:08
合計ジャッジ時間 1,937 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1890.cc:  No.1890 Many Sequences Sum Queries - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];
ll ss[MAX_M + 1];

/* subroutines */

/* main */

int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);

  for (int i = 0; i < n; i++) scanf("%d", as + i);

  ss[0] = 0;
  int m = 1;
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= as[i]; j++, m++)
      ss[m] = ss[m - 1] + j;
  //for (int i = 0; i < m; i++) printf("%lld ", ss[i]); putchar('\n');

  while (qn--) {
    int si;
    scanf("%d", &si);

    int k = lower_bound(ss, ss + m, si) - ss;
    printf("%d\n", (k >= m) ? -1 : k);
  }
  return 0;
}
0