답안 #530954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530954 2022-02-27T08:05:33 Z Slavita Akcija (COCI21_akcija) C++14
90 / 110
1556 ms 524292 KB
#include <bits/stdc++.h>
#pragma optimize("O3")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ve vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define si(v) (int)v.size()
#define en '\n'
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_muiltiset tree<int, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>
//#define int long long
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

const int N = 2e3 + 228;
const int big = 1e9 + 228;
const ll llbig = 1e18 + 228;
//ordered_set os; // os.order_of_key(4), (*os.find_by_order(5))
int n, m, ans, k;
pair<ll, ll> a[N];
set<ll> dp[N][N];

bool cmp(pair<ll, ll> a, pair<ll, ll> b){
    if (a.se <= b.se) return 1;
    return 0;
}

void upd(ll &a, ll b){
    if (a > b) {a = b;}
}

//#undef int
int main(){
    //#define int long long
    iostream::sync_with_stdio(false); cin.tie(0); ios_base::sync_with_stdio(false); cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> a[i].fi >> a[i].se;
    }
    stable_sort(a + 1, a + n + 1, cmp);

    dp[0][0].insert(0);
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= n; j++){
            int kol = 0;
            for (auto item : dp[i][j]){
                kol++;
                if (kol > k) break;
                dp[i + 1][j].insert(item);
            }
            while(si(dp[i + 1][j]) > k) dp[i + 1][j].erase(--dp[i + 1][j].end());

            if (j + 1 <= a[i + 1].se) {
                kol = 0;
                for (auto item : dp[i][j]){
                    kol++;
                    if (kol > k) break;
                    dp[i + 1][j + 1].insert(item + a[i + 1].fi);
                }
            }
            while(si(dp[i + 1][j + 1]) > k) dp[i + 1][j + 1].erase(--dp[i + 1][j + 1].end());
        }
    }

    set<pair<ll, ll>> ans;
    for (int j = 1; j <= n; j++) {
        for (auto item : dp[n][j]){
            ans.insert({-j, item});
        }
    }

    int kol = 0;
    for (auto item : ans){
        kol++;
        if (kol > k) break;
        cout << -item.fi << ' ' << item.se << en;
    }

    if (kol <= k){
        for (int i = kol + 1; i <= k; i++) cout << 0 << ' ' << 0 << en;
    }
    return 0;
}
/*
*/

Compilation message

Main.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    2 | #pragma optimize("O3")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 318892 KB Output is correct
2 Correct 240 ms 324804 KB Output is correct
3 Correct 216 ms 309368 KB Output is correct
4 Correct 215 ms 310484 KB Output is correct
5 Correct 241 ms 323268 KB Output is correct
6 Correct 115 ms 233644 KB Output is correct
7 Correct 116 ms 233984 KB Output is correct
8 Correct 113 ms 233880 KB Output is correct
9 Correct 119 ms 235388 KB Output is correct
10 Correct 142 ms 253680 KB Output is correct
11 Correct 102 ms 233440 KB Output is correct
12 Correct 101 ms 233408 KB Output is correct
13 Correct 101 ms 233412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 318892 KB Output is correct
2 Correct 240 ms 324804 KB Output is correct
3 Correct 216 ms 309368 KB Output is correct
4 Correct 215 ms 310484 KB Output is correct
5 Correct 241 ms 323268 KB Output is correct
6 Correct 115 ms 233644 KB Output is correct
7 Correct 116 ms 233984 KB Output is correct
8 Correct 113 ms 233880 KB Output is correct
9 Correct 119 ms 235388 KB Output is correct
10 Correct 142 ms 253680 KB Output is correct
11 Correct 102 ms 233440 KB Output is correct
12 Correct 101 ms 233408 KB Output is correct
13 Correct 101 ms 233412 KB Output is correct
14 Correct 302 ms 319072 KB Output is correct
15 Correct 317 ms 324720 KB Output is correct
16 Correct 283 ms 309460 KB Output is correct
17 Correct 285 ms 310532 KB Output is correct
18 Correct 316 ms 323280 KB Output is correct
19 Correct 116 ms 233588 KB Output is correct
20 Correct 119 ms 233912 KB Output is correct
21 Correct 118 ms 233740 KB Output is correct
22 Correct 126 ms 235392 KB Output is correct
23 Correct 174 ms 253784 KB Output is correct
24 Correct 102 ms 233396 KB Output is correct
25 Correct 105 ms 233396 KB Output is correct
26 Correct 106 ms 233408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 520 ms 404360 KB Output is correct
2 Correct 554 ms 416068 KB Output is correct
3 Correct 468 ms 385136 KB Output is correct
4 Correct 466 ms 387520 KB Output is correct
5 Correct 533 ms 413124 KB Output is correct
6 Correct 132 ms 233708 KB Output is correct
7 Correct 137 ms 234512 KB Output is correct
8 Correct 118 ms 233988 KB Output is correct
9 Correct 127 ms 237204 KB Output is correct
10 Correct 210 ms 273744 KB Output is correct
11 Correct 110 ms 233464 KB Output is correct
12 Correct 113 ms 233424 KB Output is correct
13 Correct 105 ms 233604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 241220 KB Output is correct
2 Correct 140 ms 241520 KB Output is correct
3 Correct 126 ms 239444 KB Output is correct
4 Correct 124 ms 238148 KB Output is correct
5 Correct 140 ms 242196 KB Output is correct
6 Correct 109 ms 233388 KB Output is correct
7 Correct 110 ms 235580 KB Output is correct
8 Correct 105 ms 234256 KB Output is correct
9 Correct 105 ms 233956 KB Output is correct
10 Correct 108 ms 233404 KB Output is correct
11 Correct 102 ms 233388 KB Output is correct
12 Correct 105 ms 233552 KB Output is correct
13 Correct 128 ms 238924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 254020 KB Output is correct
2 Correct 190 ms 253376 KB Output is correct
3 Correct 175 ms 250252 KB Output is correct
4 Correct 174 ms 250164 KB Output is correct
5 Correct 199 ms 254224 KB Output is correct
6 Correct 103 ms 233540 KB Output is correct
7 Correct 116 ms 235468 KB Output is correct
8 Correct 107 ms 234332 KB Output is correct
9 Correct 112 ms 235244 KB Output is correct
10 Correct 126 ms 238660 KB Output is correct
11 Correct 108 ms 233420 KB Output is correct
12 Correct 103 ms 233408 KB Output is correct
13 Correct 122 ms 237408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 318892 KB Output is correct
2 Correct 240 ms 324804 KB Output is correct
3 Correct 216 ms 309368 KB Output is correct
4 Correct 215 ms 310484 KB Output is correct
5 Correct 241 ms 323268 KB Output is correct
6 Correct 115 ms 233644 KB Output is correct
7 Correct 116 ms 233984 KB Output is correct
8 Correct 113 ms 233880 KB Output is correct
9 Correct 119 ms 235388 KB Output is correct
10 Correct 142 ms 253680 KB Output is correct
11 Correct 102 ms 233440 KB Output is correct
12 Correct 101 ms 233408 KB Output is correct
13 Correct 101 ms 233412 KB Output is correct
14 Correct 302 ms 319072 KB Output is correct
15 Correct 317 ms 324720 KB Output is correct
16 Correct 283 ms 309460 KB Output is correct
17 Correct 285 ms 310532 KB Output is correct
18 Correct 316 ms 323280 KB Output is correct
19 Correct 116 ms 233588 KB Output is correct
20 Correct 119 ms 233912 KB Output is correct
21 Correct 118 ms 233740 KB Output is correct
22 Correct 126 ms 235392 KB Output is correct
23 Correct 174 ms 253784 KB Output is correct
24 Correct 102 ms 233396 KB Output is correct
25 Correct 105 ms 233396 KB Output is correct
26 Correct 106 ms 233408 KB Output is correct
27 Correct 520 ms 404360 KB Output is correct
28 Correct 554 ms 416068 KB Output is correct
29 Correct 468 ms 385136 KB Output is correct
30 Correct 466 ms 387520 KB Output is correct
31 Correct 533 ms 413124 KB Output is correct
32 Correct 132 ms 233708 KB Output is correct
33 Correct 137 ms 234512 KB Output is correct
34 Correct 118 ms 233988 KB Output is correct
35 Correct 127 ms 237204 KB Output is correct
36 Correct 210 ms 273744 KB Output is correct
37 Correct 110 ms 233464 KB Output is correct
38 Correct 113 ms 233424 KB Output is correct
39 Correct 105 ms 233604 KB Output is correct
40 Correct 134 ms 241220 KB Output is correct
41 Correct 140 ms 241520 KB Output is correct
42 Correct 126 ms 239444 KB Output is correct
43 Correct 124 ms 238148 KB Output is correct
44 Correct 140 ms 242196 KB Output is correct
45 Correct 109 ms 233388 KB Output is correct
46 Correct 110 ms 235580 KB Output is correct
47 Correct 105 ms 234256 KB Output is correct
48 Correct 105 ms 233956 KB Output is correct
49 Correct 108 ms 233404 KB Output is correct
50 Correct 102 ms 233388 KB Output is correct
51 Correct 105 ms 233552 KB Output is correct
52 Correct 128 ms 238924 KB Output is correct
53 Correct 192 ms 254020 KB Output is correct
54 Correct 190 ms 253376 KB Output is correct
55 Correct 175 ms 250252 KB Output is correct
56 Correct 174 ms 250164 KB Output is correct
57 Correct 199 ms 254224 KB Output is correct
58 Correct 103 ms 233540 KB Output is correct
59 Correct 116 ms 235468 KB Output is correct
60 Correct 107 ms 234332 KB Output is correct
61 Correct 112 ms 235244 KB Output is correct
62 Correct 126 ms 238660 KB Output is correct
63 Correct 108 ms 233420 KB Output is correct
64 Correct 103 ms 233408 KB Output is correct
65 Correct 122 ms 237408 KB Output is correct
66 Runtime error 1556 ms 524292 KB Execution killed with signal 9
67 Halted 0 ms 0 KB -