跳到正文

题解

题解:AT_past17_c 換金

ravenzelda约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年2月9日
更新
2026年11月11日
篇幅
约 1 分钟

版本

  1. v1当前

思路

可以使用类似桶的思想,将 pp 数组作为一个桶,每次读入一个 aa 后就累加一次即可。

代码

C++
#include<bits/stdc++.h>
#define int long long//注意要开long long!!!
using namespace std;
int n, a[20], p[20], ans;
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= 10; i++)cin >> p[i];
	for (int i = 1; i <= n; i++)ans += p[a[i]];
	cout << ans << endl;
	return 0;
}
原文