using namespace std;
int n_card[1005];
priority_queue que[1005];
int main()
{
int n,m;
cin >> n >> m;
for(int i = 1;i <= n;i = i + 1)
{
cin >> n_card[i];
}
for(int i = 1;i <= m;i = i + 1)
{
int x,y;
cin >> x >> y;
que[x].push(y);
}
int sum = 0;
for(int i = 1;i <= n;i = i + 1)
{
if(!que[i].empty())//队列为空则说明这种类型的闪卡卖不出去
sum = sum + que[i].top() * n_card[i];
}
cout << sum << endl;
}
include
using namespace std;
int n_card[1005];
priority_queue que[1005];
int main()
{
int n,m;
cin >> n >> m;
for(int i = 1;i <= n;i = i + 1)
{
cin >> n_card[i];
}
for(int i = 1;i <= m;i = i + 1)
{
int x,y;
cin >> x >> y;
que[x].push(y);
}
int sum = 0;
for(int i = 1;i <= n;i = i + 1)
{
if(!que[i].empty())//队列为空则说明这种类型的闪卡卖不出去
sum = sum + que[i].top() * n_card[i];
}
cout << sum << endl;
}