結果
問題 | No.1093 区間の和 / Sum of Range |
ユーザー |
|
提出日時 | 2020-06-28 01:31:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 479 bytes |
コンパイル時間 | 2,994 ms |
コンパイル使用メモリ | 197,576 KB |
最終ジャッジ日時 | 2025-01-11 13:09:37 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | int n,k; scanf("%d%d",&n,&k); | ~~~~~^~~~~~~~~~~~~~ main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:22:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | int q; scanf("%d",&q); | ~~~~~^~~~~~~~~ main.cpp:24:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | int x; scanf("%d",&x); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int n,k; scanf("%d%d",&n,&k); vector<int> a(n); rep(i,n) scanf("%d",&a[i]); vector<int> S; int sum=0; rep(i,k-1) sum+=a[i]; for(int i=k-1;i<n;i++){ sum+=a[i]; S.emplace_back(sum); sum-=a[i-k+1]; } sort(S.begin(),S.end()); int q; scanf("%d",&q); rep(_,q){ int x; scanf("%d",&x); printf("%ld\n",upper_bound(S.begin(),S.end(),x)-S.begin()); } return 0; }