Computer College Undergraduate Program Design contest (2015 ' 11) 1008 Playground

Source: Internet
Author: User
Tags ming
1008 Playground Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Problem Description as a child, because the family financial difficulties, Xiaoming has never been to the playground, so until now, he still has regrets.
Recently, Hangzhou has just built a playground, in order to make up for the regret of childhood, Xiao Ming brought a sum of money can't wait to experience some.
Because it is the first time to come to such a place, xiaoming does not know which items are more fun, so he wants to experience as many projects as possible. Before coming, Xiaoming also asked a friend about the playground situation, as long as the friend recommended, he must experience. Of course, each project needs a certain cost, when Xiao Ming's money is not enough to play again.

Now, know the money of xiaoming and the cost of each game item, how many projects xiaoming can experience at most.

Input enter the first behavior of an integer t, which indicates that there is a T group of test data.

For each set of data:
The first line is three integers n, m, K, which means the number of games in the playground, the number of game items recommended by friends, and the amount of money in Xiao Ming's body (1<=m<=n<=10000, 1<=k<=10^9).
The second row is n integers, and the first integer XI represents the cost of the first game item (1&LT;=XI&LT;=10^9).
The third line is the M integer pi, which indicates that the friend recommended the PI game item (1<=pi<=n).

Output if Xiao Ming brings the money even the friend recommended items can not be all experience, please output-1; otherwise, please output the maximum number of items that xiaoming can experience.

One row for each set of outputs.

Sample Input
2 5 2 10 4 3 8 1 12 1 2 5 2 10 4 3 8 1 12 1-3
Sample Output
3-1
#include <stdio.h> #include <math.h> #include <algorithm> #include <iostream> using namespace
Std
const int N = 10005;
const int M = 10005;
const int inf = 1000000007;
const int mod = 2009;
int s[n];
    int main () {int t,n,m,k,i,x,ans;
    BOOL Flag;
    scanf ("%d", &t);
        while (t--) {flag=true;
        ans=0;
        scanf ("%d%d%d", &n,&m,&k);
        For (I=1 i<=n; i++) scanf ("%d", &s[i]);
            For (i=0 i<m; i++) {scanf ("%d", &x);
            K-=S[X];
            ans++;
            if (k<0) Flag=false;
        S[x]=inf;
            } if (!flag) {puts ("-1");
        Continue
        Sort (s+1,s+1+n);
                For (I=1 i<=n; i++) if (k>=s[i)) {ans++;
            K-=s[i];
        else break;
    printf ("%d\n", ans);
return 0;
 }

Always looking at once space in a daze, those who say not separate friends, turn around, strangers. Familiar, quiet, quiet, left, left, unfamiliar, unfamiliar, disappeared, disappeared, strangers.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.