Created
December 24, 2015 23:09
-
-
Save karupayun/ae89566a27e9c04a7608 to your computer and use it in GitHub Desktop.
Solución al problema C del Good Bye 2014 by Tourist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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