답안 #531015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531015 2022-02-27T10:34:31 Z N1NT3NDO Akcija (COCI21_akcija) C++14
20 / 110
204 ms 16832 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) (int)x.size()
#define fi first
#define sd second
#define all(x) x.begin(), x.end()
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

//#define int long long

const int N = 2100;
vector< pair<ll, ll> >  vec;
int n, k;

vector< pair<ll, ll> > ans;

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

bool cmp1(pair<ll, ll> a, pair<ll, ll> b)
{
    if (a.fi < b.fi) return 0;
    else if (a.fi == b.fi)
    {
        if (a.sd < b.sd)
          return 1;
        else return 0;
    }
    else return 1;
}

void solve_slow()
{
    for(int mask = 0; mask < (1 << n); mask++)
    {
        int cur_time = 0, skok = 0;
        ll sum = 0;
        bool ok = 1;
        for(int i = 0; i < n; i++)
        {
            if ((mask >> i) & 1)
            {
                if (cur_time < vec[i].sd)
                {
                    cur_time++;
                    skok++;
                    sum += vec[i].fi;
                }
                else ok = 0;
            }
        }

        if (ok)
          ans.pb({skok, sum});
    }

    sort(all(ans), cmp1);

    for(int i = 0; i < k; i++)
    {
        if (i >= sz(ans)) cout << 0 << ' ' << 0 << '\n';
        else cout << ans[i].fi << ' ' << ans[i].sd << '\n';
    }
}


bool cmp2(pair<ll, ll> a, pair<ll, ll> b)
{
    if (a.fi < b.fi) return 1;
    else if (a.fi == b.fi) return a.sd < b.sd;
    else return 0;
}

void solve1()
{
    int cur_time = 0, skok = 0;

    ll sum = 0;
    sort(all(vec), cmp2);
    for(auto u : vec)
    {
        if (cur_time < u.sd)
        {
            cur_time++;
            skok++;
            sum += u.fi;
        }
    }

    cout << skok << ' ' << sum;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    vec.resize(n);
    for(auto &u : vec) cin >> u.fi >> u.sd;
    sort(all(vec), cmp);
    if (n <= 20) solve_slow();
    else if (k == 1) solve1();

}

/*
3 1
1 1
2 1
2 2
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 8616 KB Output is correct
2 Correct 204 ms 16816 KB Output is correct
3 Correct 48 ms 4460 KB Output is correct
4 Correct 31 ms 2504 KB Output is correct
5 Correct 173 ms 16832 KB Output is correct
6 Correct 15 ms 204 KB Output is correct
7 Correct 72 ms 840 KB Output is correct
8 Correct 18 ms 420 KB Output is correct
9 Correct 20 ms 332 KB Output is correct
10 Correct 34 ms 312 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 56 ms 4540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Halted 0 ms 0 KB -