QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 1024 MB

#23942. Difference

통계

問題文

整数 K と,長さ N の整数列 A=(A1,A2,…,AN) および長さ M の整数列 B=(B1,B2,…,BM) が与えられる.

次の条件をすべて満たす 2 つの整数の組 (p,q) の個数を求めよ.

  • 1 ≦ p ≦ N.
  • 1 ≦ q ≦ M.
  • Ap+ K = Bq.

制約

  • 1 ≦ K ≦ 100.
  • 1 ≦ N ≦ 100.
  • 1 ≦ M ≦ 100.
  • 1 ≦ Ai≦ 100 (1 ≦ i ≦ N).
  • 1 ≦ Bj≦ 100 (1 ≦ j ≦ M).
  • 入力される値はすべて整数である.

入力

入力は以下の形式で与えられる.
K
N
A1 A2 … AN
M
B1 B2 … BM

出力

条件をすべて満たす 2 つの整数の組 (p,q) の個数を出力せよ.

答え以外は何も出力しないこと.(入力を促す文章なども出力しないこと.)

解答形式については,練習問題やその解答例 を参考にしても良い.


入力例 1

1
4
1 8 6 8
3
7 9 4

出力例 1

3
  • A2= 8, B2= 9 であり,A2+ 1 = B2 を満たすため,整数の組 (2,2) は条件を満たす.
  • A3= 6, B1= 7 であり,A3+ 1 = B1 を満たすため,整数の組 (3,1) は条件を満たす.
  • A4= 8, B2= 9 であり,A4+ 1 = B2 を満たすため,整数の組 (4,2) は条件を満たす.

条件を満たす整数の組は (2,2),(3,1),(4,2) の 3 個である.したがって 3 を出力する.


入力例 2

66
4
31 41 59 26
5
29 97 92 45 8

出力例 2

2
  • A1= 31, B2= 97 であり,A1+ 66 = B2 を満たすため,整数の組 (1,2) は条件を満たす.
  • A4= 26, B3= 92 であり,A4+ 66 = B3 を満たすため,整数の組 (4,3) は条件を満たす.

条件を満たす整数の組は (1,2),(4,3) の 2 個である.したがって 2 を出力する.


入力例 3

99
5
1 1 1 1 1
6
100 100 100 100 100 100

出力例 3

30
  • 条件を満たす整数の組は 30 個ある.したがって 30 を出力する.

入力例 4

100
1
11
1
18

出力例 4

0
  • 条件を満たす整数の組は存在しない.したがって 0 を出力する.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.