202112-1序列查询
#include<iostream>
using namespace std;
int main() {
int num, N;
int A[10000001] = { 0 };//注意题目中给定的数据范围
cin >> num >> N;
int sum = 0;
for (int i = 1; i <= num; i++) {
cin >> A[i];
}
for (int j = 0; j <num; j++) {
sum += (A[j + 1] - A[j]) * j;//求第一种情况(x<An)
}
sum += (N - A[num]) * num;//求第二种情况(x>=An)
cout << sum << endl;
return 0;//记得return 0;
}