Skip to content

Instantly share code, notes, and snippets.

@karupayun
Created December 24, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karupayun/ae89566a27e9c04a7608 to your computer and use it in GitHub Desktop.
Save karupayun/ae89566a27e9c04a7608 to your computer and use it in GitHub Desktop.
Solución al problema C del Good Bye 2014 by Tourist
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
using namespace std;
const int N = 1234567;
int w[N], a[N];
bool was[N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", w + i);
}
for (int i = 0; i < m; i++) {
scanf("%d", a + i);
}
long long ans = 0;
for (int i = 0; i < m; i++) {
for (int j = 1; j <= n; j++) {
was[j] = false;
}
for (int j = i - 1; j >= 0; j--) {
if (a[j] == a[i]) {
break;
}
if (was[a[j]]) {
continue;
}
was[a[j]] = true;
ans += w[a[j]];
}
}
cout << ans << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment