Submission #904078

# Submission time Handle Problem Language Result Execution time Memory
904078 2024-01-11T19:46:11 Z SalihSahin Akcija (COCI21_akcija) C++17
90 / 110
5000 ms 26696 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;
      |            ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 6 ms 604 KB Output is correct
5 Correct 6 ms 604 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 0 ms 344 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 6 ms 604 KB Output is correct
5 Correct 6 ms 604 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 0 ms 344 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 34 ms 604 KB Output is correct
15 Correct 36 ms 596 KB Output is correct
16 Correct 34 ms 856 KB Output is correct
17 Correct 31 ms 604 KB Output is correct
18 Correct 36 ms 640 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 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 3 ms 604 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 600 KB Output is correct
2 Correct 87 ms 672 KB Output is correct
3 Correct 65 ms 600 KB Output is correct
4 Correct 67 ms 604 KB Output is correct
5 Correct 79 ms 716 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1628 KB Output is correct
2 Correct 12 ms 1624 KB Output is correct
3 Correct 9 ms 1628 KB Output is correct
4 Correct 7 ms 1372 KB Output is correct
5 Correct 11 ms 1748 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 3 ms 668 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 10 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 860 KB Output is correct
2 Correct 13 ms 860 KB Output is correct
3 Correct 12 ms 604 KB Output is correct
4 Correct 12 ms 600 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 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 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 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 6 ms 604 KB Output is correct
5 Correct 6 ms 604 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 0 ms 344 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 34 ms 604 KB Output is correct
15 Correct 36 ms 596 KB Output is correct
16 Correct 34 ms 856 KB Output is correct
17 Correct 31 ms 604 KB Output is correct
18 Correct 36 ms 640 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 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 3 ms 604 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 76 ms 600 KB Output is correct
28 Correct 87 ms 672 KB Output is correct
29 Correct 65 ms 600 KB Output is correct
30 Correct 67 ms 604 KB Output is correct
31 Correct 79 ms 716 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 3 ms 604 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 536 KB Output is correct
40 Correct 9 ms 1628 KB Output is correct
41 Correct 12 ms 1624 KB Output is correct
42 Correct 9 ms 1628 KB Output is correct
43 Correct 7 ms 1372 KB Output is correct
44 Correct 11 ms 1748 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 4 ms 604 KB Output is correct
47 Correct 3 ms 668 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 10 ms 1372 KB Output is correct
53 Correct 16 ms 860 KB Output is correct
54 Correct 13 ms 860 KB Output is correct
55 Correct 12 ms 604 KB Output is correct
56 Correct 12 ms 600 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 344 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 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 600 KB Output is correct
66 Execution timed out 5066 ms 26696 KB Time limit exceeded
67 Halted 0 ms 0 KB -