답안 #904077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
904077 2024-01-11T19:45:22 Z SalihSahin Akcija (COCI21_akcija) C++14
90 / 110
5000 ms 27836 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
 
const int mod = 1e9 + 7;
const int inf = 1e17*2;
const int N = 2e5 + 5;
 
int32_t main(){
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int n, k;
    cin>>n>>k;
    multiset<int> best[n+2];
    best[0].insert(0);
    vector<pair<int, int> > a(n);
    for(int i = 0; i < n; i++){
        cin>>a[i].second>>a[i].first;
    }
    sort(a.begin(), a.end());

    for(int i = 0; i < n; i++){
        for(int j = a[i].first-1; j >= 0; j--){
            for(auto itr: best[j]){
                int val = a[i].second + itr;
                if(best[j+1].size() >= k){
                    auto kp = best[j+1].rbegin();
                    if(val < *kp){
                        best[j+1].insert(val);
                        if(best[j+1].size() > k){
                            auto p = best[j+1].end();
                            p--;
                            best[j+1].erase(p);
                        }
                    }
                    else break;
                }
                else{
                    best[j+1].insert(val);
                }
            }
            
        }
    }

    vector<pair<int, int> > ans;
    for(int i = n; i >= 0; i--){
        for(auto itr: best[i]){
            ans.pb(mp(i, itr));
        }
        if(ans.size() > k) break;
    }

    for(int i = 0; i < k; i++){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:28:37: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   28 |                 if(best[j+1].size() >= k){
      |                    ~~~~~~~~~~~~~~~~~^~~~
Main.cpp:32:45: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   32 |                         if(best[j+1].size() > k){
      |                            ~~~~~~~~~~~~~~~~~^~~
Main.cpp:53:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   53 |         if(ans.size() > k) break;
      |            ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 604 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 7 ms 604 KB Output is correct
5 Correct 7 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 604 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 7 ms 604 KB Output is correct
5 Correct 7 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 33 ms 604 KB Output is correct
15 Correct 37 ms 604 KB Output is correct
16 Correct 30 ms 588 KB Output is correct
17 Correct 34 ms 604 KB Output is correct
18 Correct 46 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 4 ms 860 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 696 KB Output is correct
2 Correct 86 ms 604 KB Output is correct
3 Correct 66 ms 660 KB Output is correct
4 Correct 71 ms 712 KB Output is correct
5 Correct 79 ms 736 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 612 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1628 KB Output is correct
2 Correct 11 ms 1476 KB Output is correct
3 Correct 8 ms 1372 KB Output is correct
4 Correct 8 ms 1372 KB Output is correct
5 Correct 10 ms 1628 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 8 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 860 KB Output is correct
2 Correct 14 ms 860 KB Output is correct
3 Correct 13 ms 604 KB Output is correct
4 Correct 13 ms 604 KB Output is correct
5 Correct 15 ms 860 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 4 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 604 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 7 ms 604 KB Output is correct
5 Correct 7 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 33 ms 604 KB Output is correct
15 Correct 37 ms 604 KB Output is correct
16 Correct 30 ms 588 KB Output is correct
17 Correct 34 ms 604 KB Output is correct
18 Correct 46 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 4 ms 860 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 73 ms 696 KB Output is correct
28 Correct 86 ms 604 KB Output is correct
29 Correct 66 ms 660 KB Output is correct
30 Correct 71 ms 712 KB Output is correct
31 Correct 79 ms 736 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 3 ms 612 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 13 ms 1628 KB Output is correct
41 Correct 11 ms 1476 KB Output is correct
42 Correct 8 ms 1372 KB Output is correct
43 Correct 8 ms 1372 KB Output is correct
44 Correct 10 ms 1628 KB Output is correct
45 Correct 0 ms 452 KB Output is correct
46 Correct 4 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 8 ms 1372 KB Output is correct
53 Correct 17 ms 860 KB Output is correct
54 Correct 14 ms 860 KB Output is correct
55 Correct 13 ms 604 KB Output is correct
56 Correct 13 ms 604 KB Output is correct
57 Correct 15 ms 860 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 2 ms 348 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 4 ms 536 KB Output is correct
66 Execution timed out 5036 ms 27836 KB Time limit exceeded
67 Halted 0 ms 0 KB -