Submission #97990

# Submission time Handle Problem Language Result Execution time Memory
97990 2019-02-19T17:33:06 Z dalgerok San (COCI17_san) C++17
24 / 120
1000 ms 4088 KB
#include<bits/stdc++.h>
using namespace std;




int 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];
    for(int i = 0; i < n; i++){
        cin >> h[i] >> g[i];
    }
    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();
    map < int, vector < long long > > s;
    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 != -1 && 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(auto &it : s){
        sort(it.second.begin(), it.second.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;
        for(int j = 0; j < sz; j++){
            if((i >> j) & 1){
                if(cur != -1 && cur > a[j].first){
                    p = false;
                    break;
                }
                cur = a[j].first;
                sum += a[j].second;
            }
        }
        if(!p){
            continue;
        }
        if(sum >= k){
            ans += 1;
        }
        for(auto it : s){
            if(it.first <= cur){
                ans += (int)it.second.size() - (lower_bound(it.second.begin(), it.second.end(), k - sum) - it.second.begin());
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Incorrect 3 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1046 ms 1088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 4088 KB Time limit exceeded
2 Halted 0 ms 0 KB -