Tổng trung bình bằng K

View as PDF

Submit solution

Points: 0.01 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Author:
Problem type
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

Cho mảng ~A~ gồm ~n~ số nguyên. Nhiệm vụ của bạn là đếm số lượng cặp chỉ số ~(l,r)\ (1\le l\le r\le n)~ sao cho trung bình cộng giá trị của các phần tử ~A_l,A_{l+1},\dots,A_r~ bằng ~K~.

Input

Dòng đầu tiên gồm hai số nguyên ~n,K~ tương ứng với số lượng phần tử và giá trị trung bình cộng ~K~ ~(1\le n\le 10^5,|K|\le 10^6)~.

Dòng thứ hai gồm ~n~ số nguyên ~A_1,A_2,\dots,A_n~ tương ứng với các phần tử trong dãy ~(|A_i|\le 10^6)~.

Output

In ra duy nhất một giá trị là số lượng cặp số thỏa mãn.

Sample Input 1

5 1
-3 2 -4 1 5

Sample Output 1

2

Notes

Có hai cặp số thỏa mãn là ~(2,5)~ và ~(4,4)~.


Comments

Please read the guidelines before commenting.



  • -1
    nguyenkhiem69  commented on Feb. 11, 2026, 7:05 a.m.

    n,k=map(int,input().split()) a=list(map(int,input().split())) cout=0 pref=[0]*(n+1) for i in range(1,n+1): pref[i]=pref[i-1]+a[i-1] for i in range(n): for j in range(i+1,n+1): if (pref[j]-pref[i])/(j-i)==k: cout+=1 print(cout)


  • -1
    nguyenkhiem69  commented on Feb. 11, 2026, 7:05 a.m.

    n,k=map(int,input().split()) a=list(map(int,input().split())) cout=0 pref=[0]*(n+1) for i in range(1,n+1): pref[i]=pref[i-1]+a[i-1] for i in range(n): for j in range(i+1,n+1): if (pref[j]-pref[i])/(j-i)==k: cout+=1 print(cout)