专栏文章
题解:P12006 【MX-X10-T2】[LSOT-4] 网易云
P12006题解参与者 3已保存评论 2
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @miprgwiw
- 此快照首次捕获于
- 2025/12/03 16:44 3 个月前
- 此快照最后确认于
- 2025/12/03 16:44 3 个月前
原题传送门
思路
我们可以开一个桶数组记录一下每首歌听的次数,然后遍历一遍,依次让每首歌清零,答案就为每首歌的数量乘上组合值,再更新下首歌的数量。
代码
CPP#include<bits/stdc++.h>
#define int long long
#define inf 0x7f7f7f7f
using namespace std;
const int maxn = 100010;
inline int read() {
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int n , m , a[maxn] , tong[maxn];
signed main() {
n = read();
m = read();
for(int i = 1; i < n; i++) a[i] = read();
for(int i = 1; i <= m; i++) {
int u = read() , v = read();
tong[u] += v;
}
int ans = 0;
for(int i = 1; i < n; i++) {
ans += tong[i] * a[i];
tong[i + 1] -= tong[i];
tong[i] -= tong[i];
}
for(int i = 1; i <= n; i++) {
if(tong[i]) {
cout << "Impossible" << endl;
return 0;
}
}
cout << ans << endl;
return 0;
}
相关推荐
评论
共 2 条评论,欢迎与作者交流。
正在加载评论...