solution
- 土地需要连续,联想到用前缀和。用前缀和表示前i块土地的总价钱,易得任意片连续的土地价格
#include<iostream>
using namespace std;
const int maxn = 1e4 + 10;
int main(){int n, m, price[maxn] = {0}, ans = 0;scanf("%d%d", &n, &m);for(int i = 1; i <= n; i++){scanf("%d", price + i);price[i] += price[i - 1];}for(int i = 1; i <= n; i++){for(int j = i; j <= n; j++){if(price[j] - price[i - 1] <= m) ans++;}}printf("%d", ans);return 0;
}