답안 #767760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
767760 2023-06-27T06:55:00 Z dxz05 Akcija (COCI21_akcija) C++17
0 / 110
4 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
#define BIT(x, i) (((x) >> (i)) & 1)
//#define endl '\n'

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 1e6 + 3e2;

void solve(){
    int n, k;
    cin >> n >> k;

    multiset<pair<int, ll>> best;

    function<void(int, ll)> add = [&](int x, ll y){
        y = -y;
        if (best.size() < k){
            best.emplace(x, y);
        } else if (*best.begin() < MP(x, y)){
            best.erase(best.begin());
            best.emplace(x, y);
        }
    };

    add(0, 0);

    for (int i = 1; i <= n; i++){
        int w, d;
        cin >> w >> d;

        multiset<pair<int, ll>> s = best;
        for (auto [x, y] : s){
            y = -y;
            if (x < d) add(x + 1, y + w);
        }
    }

    for (auto it = best.rbegin(); it != best.rend(); it++){
        cout << it->first << ' ' << -it->second << endl;
    }

}

int main(){
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int test_cases = 1;
//    cin >> test_cases;

    for (int test = 1; test <= test_cases; test++){
        // cout << (solve() ? "YES" : "NO") << endl;
        solve();
    }

#ifdef LOCAL
    cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif

    return 0;
}

Compilation message

Main.cpp: In lambda function:
Main.cpp:27:25: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |         if (best.size() < k){
      |             ~~~~~~~~~~~~^~~
Main.cpp: In function 'int main()':
Main.cpp:55:13: warning: unused variable 'startTime' [-Wunused-variable]
   55 |     clock_t startTime = clock();
      |             ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -