Submission #50601

# Submission time Handle Problem Language Result Execution time Memory
50601 2018-06-11T21:33:25 Z XmtosX San (COCI17_san) C++17
120 / 120
607 ms 68428 KB
#include <bits/stdc++.h>
using namespace std;
vector <long long> v2[40];
vector <pair<long long ,int> > v1;
int n;
long long k,h[50],c[50];
void bt (int pos,int x,long long first,int last,long long sum)
{
    if (pos==x)
    {
        if (x!=n+1)
            v1.push_back({sum,last});
        else
        {
            for (int i=0;i<=n/2+1;i++)
                if (first>=h[i]) v2[i].push_back(sum);
        }
        return ;
    }
    if (h[pos]>=h[last])
        bt(pos+1,x,min(first,h[pos]),pos,sum+c[pos]);
    bt(pos+1,x,first,last,sum);
}
int main()
{
    cin >>n>>k;
    for (int i=1;i<=n;i++)
        cin >>h[i]>>c[i];
    if (n==1)
    {
        cout << (k<=c[1]);
        return 0;
    }
    bt(1,n/2+2,1e12,0,0);
    bt(n/2+2,n+1,1e12,0,0);
    for (int i=0;i<=n/2+1;i++)
        sort(v2[i].begin(),v2[i].end());
    long long ans=0;
    for (int i=0;i<v1.size();i++)
    {
        int idx= v1[i].second;
        long long sum= v1[i].first;
        sum= (k-sum);
        int p1= lower_bound(v2[idx].begin(),v2[idx].end(),sum)-v2[idx].begin();
        ans+= (v2[idx].size()-p1);
    }
    cout <<ans;
    return 0;
}

Compilation message

san.cpp: In function 'int main()':
san.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<v1.size();i++)
                  ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 472 KB Output is correct
2 Correct 3 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 6520 KB Output is correct
2 Correct 5 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 18292 KB Output is correct
2 Correct 10 ms 18292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 607 ms 68428 KB Output is correct
2 Correct 46 ms 68428 KB Output is correct