文章目录
- C++
- 总结
本题链接:CSP 202112-1 序列查询
本博客给出本题截图:
C++
#include <iostream> #include <algorithm> using namespace std; const int N = 210; int a[N]; int s[N]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i ++ ) cin >> a[i]; int sum = 0; for (int i = 1; i < n; i ++) s[i] = a[i + 1] - a[i]; for (int i = 1; i < n; i ++ ) sum += s[i] * i; sum += n * (m - a[n]); cout << sum << endl; return 0; }
总结
水题,不解释