Submission #458043

# Submission time Handle Problem Language Result Execution time Memory
458043 2021-08-07T20:11:33 Z JovanB San (COCI17_san) C++17
120 / 120
104 ms 21024 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

const int N = 40;

int h[N+5];
int g[N+5];

int bit[N+5];

void bit_add(int x){
    while(x <= N){
        bit[x]++;
        x += x & -x;
    }
}

int bit_get(int x){
    int res = 0;
    while(x){
        res += bit[x];
        x -= x & -x;
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    ll k;
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> h[i] >> g[i];
    vector <pair <int, int>> vc;
    for(int i=1; i<=n; i++) vc.push_back({h[i], i});
    int trr = 0;
    sort(vc.begin(), vc.end());
    for(int i=0; i<vc.size(); i++){
        if(i == 0 || vc[i].first != vc[i-1].first) trr++;
        h[vc[i].second] = trr;
    }
    vector <pair <ll, int>> v1;
    vector <pair <ll, int>> v2;
    for(int i=1; i<=n/2; i++){
        for(int j=int(v1.size())-1; j>=0; j--) if(h[v1[j].second] <= h[i]) v1.push_back({v1[j].first + g[i], i});
        v1.push_back({g[i], i});
    }
    for(int i=n; i>n/2; i--){
        for(int j=int(v2.size())-1; j>=0; j--) if(h[i] <= h[v2[j].second]) v2.push_back({v2[j].first + g[i], i});
        v2.push_back({g[i], i});
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    int j = v1.size();
    ll res = 0;
    for(auto pr : v2){
        ll coins = pr.first;
        int i = pr.second;
        while(j > 0 && coins + v1[j-1].first >= k){
            j--;
            bit_add(h[v1[j].second]);
        }
        res += bit_get(h[i]);
        if(coins >= k) res++;
    }
    for(auto pr : v1) if(pr.first >= k) res++;
    cout << res << "\n";
    return 0;
}

Compilation message

san.cpp: In function 'int main()':
san.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=0; i<vc.size(); i++){
      |                  ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2000 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5320 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 21024 KB Output is correct
2 Correct 16 ms 3588 KB Output is correct