Problem:
Problem C: Ball
Problem
$N$個のボールがあり、各ボールには色と価値が決められている。
ボールの色は$1$から$C$まで$C$種類存在し、各色ごとに選べるボールの数の上限が決められている。
ボールを全体で高々$M$個選ぶとき、得られる価値の合計を最大化せよ。
Input
入力は以下の形式で与えられる。
$N$ $M$ $C$
$l_1$ $l_2$ ... $l_C$
$c_1$ $w_1$
$c_2$ $w_2$
...
$c_N$ $w_N$
入力はすべて整数で与えられる。
1行目に$N$, $M$, $C$が空白区切りで与えられる。
2行目に色$i$の選べるボールの数の上限$l_i$($1 \leq i \leq C$)が空白区切りで与えられる。
3行目以降の$N$行にボール$i$の色$c_i$と価値$w_i$($1 \leq i \leq N$)が空白区切りで与えられる。
Constraints
入力は以下の条件を満たす。
$1 \leq M \leq N \leq 10^5 $
$1 \leq C \leq 10^5 $
$0 \leq l_i \leq N $
$1 \leq c_i \leq C $
$1 \leq w_i \leq 1000 $
Output
得られる価値の最大値を1行に出力せよ。
Sample Input 1
3 3 2
1 1
1 1
1 100
2 10
Sample Output 1
110
2番目と3番目のボールを選ぶのが最適である。
Sample Input 2
3 3 3
1 0 1
1 1
2 100
3 1
Sample Output 2
2
ある色のボールが一個も選べない場合もある。
Sample Input 3
22 7 26
11 14 15 3 11 7 16 17 1 4 2 19 4 14 16 16 3 13 17 12 7 11 2 20 12 22
6 10
1 3
13 1
16 5
4 1
20 7
18 4
26 6
9 1
12 2
21 1
21 7
18 1
14 5
24 5
6 1
3 1
2 5
21 2
7 6
10 9
15 7
Sample Output 3
52

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, m, c;
    cin >> n >> m >> c;
    vector<ll> l(c);
    rep(i, 0, c)
    {
        cin >> l[i];
    }
    vector<vector<ll>> g(c);
    rep(i, 0, n)
    {
        ll x, y;
        cin >> x >> y;
        x--;
        g[x].push_back(y);
    }
    rep(i, 0, c)
    {
        srt(g[i]);
        rev(g[i]);
    }
    vector<ll> ar;
    rep(i, 0, c)
    {
        rep(j, 0, min((ll)g[i].size(), l[i]))
        {
            ar.push_back(g[i][j]);
        }
    }
    srt(ar);
    rev(ar);
    ll ans = 0;
    rep(i, 0, min((ll)ar.size(), m))
    {
        ans += ar[i];
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 9456
final_rank: 16

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using Pi = pair<int, int>;

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> l(C);
    vector<Pi> cw(N);
    for (int i = 0; i < C; ++i) cin >> l[i];
    for (int i = 0; i < N; ++i) cin >> cw[i].second >> cw[i].first;

    std::sort(cw.begin(), cw.end(), std::greater<Pi>());

    int cnt = 0, ans = 0;
    for (int i = 0; i < N; ++i) {
        if (l[cw[i].second - 1] > 0) {
            --l[cw[i].second - 1];
            ans += cw[i].first;
            ++cnt;
        }
        if (cnt >= M) break;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 4180
final_rank: 10

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
greedy
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_C = 100000;
static int NUM[MAX_C]; // limit of each color

//------------------------------------------------------------------------------
struct Ball
{
    int v;
    int c;

    Ball(): c(-1), v(0) {}
    Ball(int color, int value): c(color), v(value) {}
    bool operator<(const Ball& other) const { return v > other.v; }
    void debug() const { printf("c=%d, v=%d\n", c, v); }
};

typedef vector<Ball> Balls;
//------------------------------------------------------------------------------
int solve(int N, Balls& B, int M, int C)
{
    //--------------------------------------------------------------------------
    // base cases:
    //--------------------------------------------------------------------------
    // init:
    sort(B.begin(), B.end());
    //--------------------------------------------------------------------------
    // compute:
    int res = 0;    
    for (Ball b: B)
    {
        if (M == 0) break;
        if (!NUM[b.c]) continue;
        NUM[b.c]--;
        res += b.v;
        M--;
    }
    //--------------------------------------------------------------------------
    // report:
    //printf("%d\n", res);
    return res;
}

//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, M, C, color, value, num;
    num = scanf("%d %d %d ", &N, &M, &C);
    for (int i=0; i<C; ++i) num = scanf("%d ", &NUM[i]);
    Balls B(N);
    for (int i=0; i<N; ++i)
    {
        num = scanf("%d %d ", &color, &value);
        color--;
        B[i] = Ball(color, value);
    }
    int res = solve(N, B, M, C);
    printf("%d\n", res);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 10
memory_kb: 4256
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;


template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (a == 0)return b;
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll sqrtz(ll N) {
    ll L = 0;
    ll R = sqrt(N) + 10000;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;

}
vvll DP(1001,vll(1001,-1));

ll dfs(ll N,ll M){
    if(DP[N][M]!=-1)return DP[N][M];
    if(N==0&&M==0)return 0;
    ll res=1e18;
    rep(i,4){
        rep(j,4){
            if(i+j==0||i+j>3)continue;
            if(i>N||j>M)continue;
            chmin(res,dfs(N-i,M-j+i)+1);
        }
    }
    DP[N][M]=res;
    return res;
}


int main() {


    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N,M,C;
    cin>>N>>M>>C;
    vll P(C);
    rep(i,C)cin>>P[i];
    vector<pair<ll,ll>> Q(N);
    rep(i,N){
        cin>>Q[i].second>>Q[i].first;
        Q[i].second--;
    }
    sort(all(Q));
    reverse(all(Q));
    ll an=0;
    rep(i,N){
        if(M>0&&P[Q[i].second]>0){
            an+=Q[i].first;
            M--;
            P[Q[i].second]--;
        }
    }
    cout<<an<<endl;

    


}
accuracy: 1
time_ms: 20
memory_kb: 13084
final_rank: 20

code_snippet: #include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<vector>
#include<string>
#include <iomanip>
#include <deque>
#include<list>
#include<cmath>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using P_S=pair<int,string>;
using P_D=pair<double,int>;
using T=tuple<int,int,char,ll,string>;

int main()
{
    int N,M,C;
    cin>>N>>M>>C;
    int l[C];
    vector<P> ball;
    rep(i,C) cin>>l[i];
    rep(i,N){
        P b;
        cin>>b.second>>b.first;
        ball.push_back(b);
    }
    sort(ball.begin(),ball.end());
    ll ans=0;
    int num=0,now=ball.size();
    for(int i=N-1;i>=0;i--){
        if(!l[ball[i].second-1]) continue;
        ans+=ball[i].first;
        l[ball[i].second-1]--;
        M--;
        if(!M) break;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 4380
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#define FastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define precision(d) fixed << setprecision(d)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

struct Ball {
  int color, weight;
  // Ball(int c, int w) : color{c}, weight{w} {}
  // compare operator
  bool operator<(const Ball& other) const { return weight > other.weight; }
};

int main() {
  FastIO;

  // ready
  int n, m, c;
  cin >> n >> m >> c;

  vector<int> colors(c + 1);
  for (int i = 1; i <= c; i++) {
    int color;
    cin >> color;
    colors[i] = color;
  }

  vector<Ball> balls(n);
  for (int i = 0; i < n; i++) {
    int c, w;
    cin >> c >> w;
    balls[i].color = c;
    balls[i].weight = w;
  }

  sort(balls.begin(), balls.end());

  // checking answer
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (colors[balls[i].color] > 0) {
      colors[balls[i].color]--;
      ans += balls[i].weight;
      m--;
    }
    if (m == 0) break;
  }

  cout << ans << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4132
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define FastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define precision(d) fixed << setprecision(d)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

struct Ball {
  int color, weight;
  Ball(int c, int w) : color{c}, weight{w} {}
  // compare operator
  bool operator<(const Ball& other) const { return weight > other.weight; }
};

int main() {
  FastIO;

  // ready
  int n, m, c;
  cin >> n >> m >> c;

  map<int, int> colors;
  for (int i = 1; i <= c; i++) {
    int color;
    cin >> color;
    colors[i] = color;
  }

  vector<Ball> balls;
  for (int i = 0; i < n; i++) {
    int c, w;
    cin >> c >> w;
    balls.emplace_back(Ball(c, w));
  }

  sort(balls.begin(), balls.end());

  // checking answer
  int ans = 0;
  while (m != 0) {
    for (const auto ball : balls) {
      // found ball
      if (colors.find(ball.color) != colors.end()) {
        if (colors[ball.color] > 0) {
          ans += ball.weight;
          colors[ball.color]--;
          m--;
        }
      }
      if (m == 0) break;
    }
    break;
  }

  cout << ans << '\n';
}
accuracy: 1
time_ms: 50
memory_kb: 8620
final_rank: 18

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in(),M=in(),C=in();
	vll L=vecin(C);
	vector<pair<ll,ll>> P(N);
	REP(i,N){
		P[i].first=in();
		P[i].second=in();
	}
	sort(ALL(P),PAIRCOMP(second,>));

	ll S=0;
	REP(i,N){
		if(L[P[i].first-1]>0){
			L[P[i].first-1]--;
			S += P[i].second;
			M--;
		}
		if(!M) break;
	}
	out(S);
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5452
final_rank: 8

code_snippet: #include<bits//stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const int MAX = 510000;
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
int main(){
    int n,m,c;cin>>n>>m>>c;
    vector<int> l(c),now(c,0);
    rep(i,c) cin >>l[i];
    priority_queue<pair<int,int>> pq;
    int C,w;
    rep(i,n){
        cin >> C>>w;pq.push({w,C-1});
    }ll sum = 0,cnt = 0;
    for(;;){
        if(cnt==m||pq.empty())break;
        pair<int,int> p = pq.top();
        pq.pop();
        if(now[p.second] < l[p.second]){
            sum += p.first;now[p.second]++;
            cnt++;
        }
    }cout << sum <<endl;
}
accuracy: 1
time_ms: 50
memory_kb: 4524
final_rank: 14

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-3, PI = acos(-1);
//ここから編集

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(6);

  int N, M, C; cin >> N >> M >> C;

  vector<int> l(C);
  REP(i,C) cin >> l[i];

  priority_queue<pair<int, int>> pq;
  int ans = 0;
  REP(i,N){
    int c, w; cin >> c >> w;
    c--;
    pq.push({w, c});
  }
  int cnt = 0;
  while(pq.size()){
    if(cnt >= M) break;
    if(l[pq.top().second] == 0){
      pq.pop();
      continue;
    }

    ans += pq.top().first;
    cnt++;
    l[pq.top().second]--;
    pq.pop();
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4128
final_rank: 4

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

using P=pair<ll,ll>;
void solve(){
  ll n,m,c;
  cin>>n>>m>>c;
  vector<ll>l(c);
  rep(i,c)cin>>l[i];
  vector<P>p(n);
  priority_queue<P>pq;
  rep(i,n){
    cin>>p[i].second>>p[i].first;
    p[i].second--;
    pq.emplace(p[i]);
  }
  ll ans=0;
  int cnt=0;
  while(!pq.empty()){
    auto x=pq.top();
    pq.pop();
    if(l[x.second]>0){
      ans+=x.first;
      ++cnt;
      l[x.second]--;
    }
    if(cnt>=m)break;
  }
  cout<<ans<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7140
final_rank: 12

code_snippet: #pragma GCC optimize ("Ofast")
#pragma GCC target ("avx")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<complex>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include<tuple>

using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(),(a).end()
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define R pair<pair<int, int>, pair<int, int>>
#define S(i,j,k,l) mkp(mkp(i,j),mkp(k,l))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define range(i,v) for(auto& (i) : v)
#define mkp make_pair
#define mem(x,k) memset(x,k,sizeof(x))
#define vec vector
#define pb emplace_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define getidx(b,i) lower_bound(all(b),(i))-b.begin()
#define ssp(i,n) (i==n-1?"\n":" ")
#define ctoi(c) (int)(c-'0')
#define itoc(c) (char)(c+'0')
#define itn int
#define pri_que priority_queue
#define pp(x,y) pb(H{x,y})
#define ppp(x,y,z) pb(Q(x,y,z))
#define pppp(x,y,z,w) pb(S(x,y,z,w))
#define cyes cout<<"Yes\n"
#define cno cout<<"No\n"
#define endl "\n"
constexpr int mod = 1e9 + 7;
constexpr int Mod = 998244353;
constexpr ll inf = 3 * 1e18;
constexpr int Inf = 15 * 1e8;
const vec<int>dx{ -1,1,0,0 }, dy{ 0,0,-1,1 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
H readh(bool g = 0) { H u; ll k = scanf("%lld %lld", &u.fs, &u.sc); if (g) u.fs--, u.sc--; return u; }
void printh(H t) { printf("%lld %lld\n", t.fs, t.sc); }
bool inarea(H t, int h, int w) { return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p = mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
	return sum;
}
/*constexpr int fn_ = 1000005;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) 
			fact_[i] = fact_[i - 1] * i % Mod;
		comp_[fn_ - 1] = mod_pow(fact_[fn_ - 1], Mod - 2, Mod);
		for (int i = fn_ - 2; i > 0; i--)
			comp_[i] = comp_[i + 1] * (i + 1) % Mod;
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//--------------------------------------------------------------

signed main() {
	int n, m, c;
	cin >> n >> m >> c;
	vec<int>l; rep(i, c) l.pb(read());
	vec<H>v; rep(i, n) v.pp(read(), read());
	for_each(all(v), [](H& i) {i.fs--; });
	sort(all(v), [](H& i, H& j) {return i.sc > j.sc; });
	int ans = 0;
	for (int i = 0; i < n && m>0; i++) {
		if (l[v[i].fs]) {
			l[v[i].fs]--;
			ans += v[i].sc;
			m--;
		}
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 5728
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 N, M, C;
  cin >> N >> M >> C;
  vector<i64> l(C);
  for (i64 i = 0; i < C; i++)
    cin >> l[i];
  vector<pair<i64, i64>> b(N);
  for (i64 i = 0; i < N; i++)
  {
    cin >> b[i].second >> b[i].first;
    b[i].second--;
  }
  sort(b.rbegin(), b.rend());
  i64 ans = 0, cnt = 0;
  for (pair<i64, i64> i : b)
  {
    if (0 < l[i.second])
    {
      ans += i.first;
      l[i.second]--;
      cnt++;
    }
    if (M <= cnt)
      break;
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4868
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define all(a) (a).begin(),(a).end()

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,c;
    cin >> n >> m >> c;
    vector<pair<int,int>> lim(c);
    vector<pair<int,int>> valc(n);
    for(int i = 0; i < c; i++){
        int x;
        cin >> x;
        lim[i] = {x,0};
    }
    for(int i = 0; i < n; i++){
        int col,val;
        cin >> col >> val;
        col--;
        valc[i] = {val,col};
    }
    sort(all(valc));
    reverse(all(valc));
    
    int cnt = 0;
    int ans = 0;
    int i = 0;
    while(cnt < m && i < n){
        pair<int,int> p;
        p = valc[i];
        if(lim[p.second].second < lim[p.second].first){
            ans += p.first;
            cnt++;
            lim[p.second].second++;
        }
        i++;
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 4212
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define all(a) (a).begin(),(a).end()

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,c;
    cin >> n >> m >> c;
    vector<pair<int,int>> lim(c);
    vector<pair<int,int>> valc(n);
    for(int i = 0; i < c; i++){
        int x;
        cin >> x;
        lim[i] = {x,0};
    }
    for(int i = 0; i < n; i++){
        int col,val;
        cin >> col >> val;
        col--;
        valc[i] = {val,col};
    }
    sort(all(valc));
    reverse(all(valc));
    
    int cnt = 0;
    int ans = 0;
    int i = 0;
    while(cnt < m && i < n){
        pair<int,int> p;
        p = valc[i];
        if(lim[p.second].second < lim[p.second].first){
            ans += p.first;
            cnt++;
            lim[p.second].second++;
        }
        i++;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 4228
final_rank: 6

code_snippet: /*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,c,l[100005]={},ans=0;
  P p[100005]={};
  cin >> n >> m >> c;
  for(int i=0; i<c; i++) {
    cin >> l[i];
  }
  for(int i=0; i<n; i++) {
    cin >> p[i].second >> p[i].first;
  }
  sort(p,p+n,greater<P>());
  for(auto a:p) {
    if(l[a.second-1]) {
      ans+=a.first;
      l[a.second-1]--;
      m--;
      if(m==0) {
        break;
      }
    }
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4784
final_rank: 3

code_snippet: /*  -*- coding: utf-8 -*-
 *
 * 3028.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_CN = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int ls[MAX_CN];
pii wcs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, cn;
  scanf("%d%d%d", &n, &m, &cn);

  for (int i = 0; i < cn; i++) scanf("%d", ls + i);

  for (int i = 0; i < n; i++) {
    int ci, wi;
    scanf("%d%d", &ci, &wi);
    ci--;
    wcs[i] = pii(wi, ci);
  }
  sort(wcs, wcs + n);

  int sum = 0;
  for (int i = n - 1; i >= 0 && m > 0; i--) {
    int &wi = wcs[i].first, &ci = wcs[i].second;
    if (ls[ci] > 0) {
      sum += wi;
      ls[ci]--;
      m--;
    }
  }

  printf("%d\n", sum);
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4308
final_rank: 7

code_snippet: #include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll ans;
ll n, m, c;
ll l[100005];
pll ball[100005];

int main()
{
    cin >> n >> m >> c;
    for (int i = 1; i <= c; i++) {
        cin >> l[i];
    }

    for (int i = 0; i < n; i++) {
        cin >> ball[i].second >> ball[i].first;
    }

    sort(ball, ball + n, greater<pll>());

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (cnt >= m) break;
        
        if (l[ball[i].second] > 0 &&
            ans + ball[i].first > ans) {
            l[ball[i].second]--;
            cnt++;
            ans += ball[i].first;
        }
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 5224
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define int long long

int n, m, c;
int l[100010];

signed main(){
    cin >> n >> m >> c;

    for(int i = 0;i < c;i++){
        cin >> l[i];
    }

    int c, w;

    priority_queue<pair<int, int> > que;

    for(int i = 0;i < n;i++){
        cin >> c >> w;
        c--;
        que.push(make_pair(w, c));
    }

    int ans = 0;

    while(!que.empty() && m > 0){
        if(l[que.top().second] > 0){
            l[que.top().second]--;
            m--;
            ans += que.top().first;
        }
        que.pop();
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 5576
final_rank: 17

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;
int n,m,c,p,ans;
int l[123456];
pair<int,int> wc[123456];
int main() {
	cin>>n>>m>>c;
	for(int i=1;i<=c;i++)cin>>l[i];
	for(int i=0;i<n;i++){
		cin>>wc[i].second>>wc[i].first;
		wc[i].first=1000-wc[i].first;
	}
	sort(wc,wc+n);
	for(int i=0;i<n&&p<m;i++){
		if(l[wc[i].second]){
			l[wc[i].second]--;p++;
			ans+=1000-wc[i].first;
		}
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4172
final_rank: 13