Submission #5597922


Source Code Expand

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    vector<pair<ll,ll>> bc(m);
    REP(i, m) cin >> bc[i].first >> bc[i].second;

    sort(ALL_OF(a));
    sort(ALL_OF(bc), [](auto &bci, auto &bcj) -> bool {
        if (bci.second != bcj.second)
            return bci.second > bcj.second;
        else
            return bci.first > bcj.first;
    });

    ll unchanged = 0;
    REP(i, m) {
        ll lb = lower_bound(a.begin() + unchanged, a.end(), bc[i].second) - a.begin();
        ll en = unchanged + min(bc[i].first, lb - unchanged);
        RANGE(j, unchanged, en-1) {
            a[j] = bc[i].second;
        }
        unchanged = en;
    }

    cout << accumulate(ALL_OF(a), 0LL) << endl;
    
}

Submission Info

Submission Time
Task D - Integer Cards
User ganmodokix
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2191 Byte
Status AC
Exec Time 122 ms
Memory 2560 KiB

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 24
AC × 4
Set Name Test Cases
All sample_01, sample_02, sample_03, sample_04, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_20
Sample sample_01, sample_02, sample_03, sample_04
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KiB
sample_02 AC 1 ms 256 KiB
sample_03 AC 1 ms 256 KiB
sample_04 AC 1 ms 256 KiB
testcase_01 AC 39 ms 896 KiB
testcase_02 AC 116 ms 2560 KiB
testcase_03 AC 91 ms 2560 KiB
testcase_04 AC 34 ms 1792 KiB
testcase_05 AC 1 ms 256 KiB
testcase_06 AC 104 ms 2432 KiB
testcase_07 AC 112 ms 2560 KiB
testcase_08 AC 56 ms 1536 KiB
testcase_09 AC 95 ms 2304 KiB
testcase_10 AC 33 ms 896 KiB
testcase_11 AC 122 ms 2560 KiB
testcase_12 AC 49 ms 1152 KiB
testcase_13 AC 111 ms 2560 KiB
testcase_14 AC 113 ms 2432 KiB
testcase_15 AC 122 ms 2560 KiB
testcase_16 AC 46 ms 1152 KiB
testcase_17 AC 90 ms 2048 KiB
testcase_18 AC 90 ms 2048 KiB
testcase_19 AC 99 ms 2560 KiB
testcase_20 AC 99 ms 2560 KiB