186192025-10-29 11:26:46ubormaciBeszerzéscpp17Accepted 50/5043ms6452 KiB
#include <iostream>
#include <cstdint>
#include <algorithm>

#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef int64_t ll;

void cerrr(vector<vector<pair<ll,ll>>> v) {

    for(const auto & j : v) {
        for(const auto & [x, y] : j) {
            cerr << "{" << x << "," << y << "},";
        }
        cerr << "\n";
    } 

}

void solve() {

    ll n, m, k;
    cin >> n >> m >> k;

    vector<vector<pair<ll,ll>>> foodtoing(n+1);

    vector<ll> ord(n+1, 0);
    vector<vector<pair<ll,ll>>> ingtofood(k+1);

    for(ll i = 1; i <= n; i++) {

        ll ingcount = 0;
        cin >> ingcount;
        foodtoing[i].resize(ingcount);

        //cerr << "\ni=" << i << "; ingcount=" << ingcount;

        for(ll j = 0; j < ingcount; j++) {
            ll ing, quantity;
            cin >> ing >> quantity;

            foodtoing[i][j] = {ing, quantity};
            ingtofood[ing].push_back({i, quantity});
        }
    }

    //cerr << "\nfoodtoing\n";
    //cerrr(foodtoing);
    //cerr << "\ningtofood\n";
    //cerrr(ingtofood);

    for(ll i = 1; i <= m; i++) {
        ll cnt;
        cin >> cnt;

        for(ll i = 0; i < cnt; i++) {
            ll food, howmany;
            cin >> food >> howmany;
            ord[food] += howmany;
        }
    }

    /*
    cerr << "\nord=";
    for(ll i = 1; i <= n; i++) {
        cerr << ord[i] << " ";
    }
    */

    vector<ll> res(k+1, 0);

    for(ll i = 1; i <= k; i++) {
        //cerr << "\ni=" << i;
        for(const auto & [f, q] : ingtofood[i]) {
            res[i] += ord[f] * q;
        }
    }

    //cerr << "\nres calced";

    for(ll i = 1; i <= k; i++) {
        cout << res[i] << " ";
    }

}

int main() {
    
    std::ios_base::sync_with_stdio(false);
    
    solve();
    
    return 0;

}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask27/7
2Accepted39ms6164 KiB
3Accepted39ms6228 KiB
4Accepted30ms6196 KiB
5Accepted30ms6204 KiB
6Accepted28ms6196 KiB
subtask312/12
7Accepted1ms316 KiB
8Accepted1ms508 KiB
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms316 KiB
12Accepted1ms316 KiB
13Accepted1ms316 KiB
14Accepted1ms500 KiB
15Accepted1ms316 KiB
16Accepted1ms316 KiB
17Accepted1ms508 KiB
subtask413/13
18Accepted39ms6164 KiB
19Accepted39ms6228 KiB
20Accepted30ms6196 KiB
21Accepted30ms6204 KiB
22Accepted28ms6196 KiB
23Accepted34ms6216 KiB
24Accepted34ms6308 KiB
25Accepted37ms6288 KiB
26Accepted35ms6384 KiB
27Accepted37ms6444 KiB
28Accepted34ms6284 KiB
29Accepted34ms6420 KiB
30Accepted37ms6452 KiB
31Accepted39ms6452 KiB
32Accepted41ms6452 KiB
33Accepted37ms6312 KiB
34Accepted35ms6328 KiB
35Accepted32ms6232 KiB
36Accepted39ms6272 KiB
subtask518/18
37Accepted1ms316 KiB
38Accepted39ms6164 KiB
39Accepted39ms6228 KiB
40Accepted30ms6196 KiB
41Accepted30ms6204 KiB
42Accepted28ms6196 KiB
43Accepted1ms508 KiB
44Accepted1ms316 KiB
45Accepted1ms316 KiB
46Accepted1ms316 KiB
47Accepted1ms316 KiB
48Accepted1ms316 KiB
49Accepted1ms500 KiB
50Accepted1ms316 KiB
51Accepted1ms316 KiB
52Accepted1ms508 KiB
53Accepted34ms6216 KiB
54Accepted34ms6308 KiB
55Accepted37ms6288 KiB
56Accepted35ms6384 KiB
57Accepted37ms6444 KiB
58Accepted34ms6284 KiB
59Accepted34ms6420 KiB
60Accepted37ms6452 KiB
61Accepted39ms6452 KiB
62Accepted41ms6452 KiB
63Accepted37ms6312 KiB
64Accepted35ms6328 KiB
65Accepted32ms6232 KiB
66Accepted39ms6272 KiB
67Accepted39ms6120 KiB
68Accepted41ms6048 KiB
69Accepted39ms5988 KiB
70Accepted37ms6084 KiB
71Accepted32ms5932 KiB
72Accepted41ms5824 KiB
73Accepted43ms5788 KiB
74Accepted37ms5804 KiB
75Accepted37ms5940 KiB
76Accepted37ms5796 KiB
77Accepted37ms6288 KiB
78Accepted34ms5948 KiB