Submission #98006

# Submission time Handle Problem Language Result Execution time Memory
98006 2019-02-19T17:53:19 Z dalgerok San (COCI17_san) C++17
120 / 120
223 ms 3032 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;




main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, sz, ans = 0;
    long long k;
    cin >> n >> k;
    int h[n], g[n];
    vector < int > e;
    for(int i = 0; i < n; i++){
        cin >> h[i] >> g[i];
        e.push_back(h[i]);
    }
    sort(e.begin(), e.end());
    e.resize(unique(e.begin(), e.end()) - e.begin());
    int esz = (int)e.size();
    for(int i = 0; i < n; i++){
        h[i] = lower_bound(e.begin(), e.end(), h[i]) - e.begin();
    }
    vector < pair < int, int > > a;
    for(int i = 0; i < n / 2; i++){
        a.push_back(make_pair(h[i], g[i]));
    }
    sz = (int)a.size();
    vector < long long > s[esz];
    for(int i = 1; i < (1 << sz); i++){
        long long sum = 0;
        bool p = true;
        int cur = -1;
        for(int j = 0; j < sz; j++){
            if((i >> j) & 1){
                if(cur > a[j].first){
                    p = false;
                    break;
                }
                cur = a[j].first;
                sum += a[j].second;
            }
        }
        if(!p){
            continue;
        }
        if(sum >= k){
            ans += 1;
        }
        s[cur].push_back(sum);
    }
    for(int i = 0; i < esz; i++){
        sort(s[i].begin(), s[i].end());
    }
    a.clear();
    for(int i = n / 2; i < n; i++){
        a.push_back(make_pair(h[i], g[i]));
    }
    sz = (int)a.size();
    for(int i = 1; i < (1 << sz); i++){
        long long sum = 0;
        bool p = true;
        int cur = -1, kek = -1;
        for(int j = 0; j < sz; j++){
            if((i >> j) & 1){
                if(cur > a[j].first){
                    p = false;
                    break;
                }
                if(cur == -1){
                    kek = a[j].first;
                }
                cur = a[j].first;
                sum += a[j].second;
            }
        }
        if(!p){
            continue;
        }
        if(sum >= k){
            ans += 1;
        }
        for(int j = 0; j <= kek; j++){
            ans += s[j].end() - lower_bound(s[j].begin(), s[j].end(), k - sum);
        }
    }
    cout << ans;
}

Compilation message

san.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 768 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1056 KB Output is correct
2 Correct 19 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 3032 KB Output is correct
2 Correct 103 ms 1716 KB Output is correct