Intellectual big Surf (riddle)

Source: Internet
Author: User

Intellectual big Surf (riddle) Title Description

Xiao Wei enrolled in CCTV's intellectual big surfing program. The challenge attracted a lot of contestants, the host to honor everyone's courage, first reward each contestant M yuan. Don't be too happy first! Because the money is not necessarily yours?! Then the host announced the rules of the game:
First of all, the game time is divided into N-period (n≤500), it gives a lot of small games, each small game must be in the stipulated period TI before completion (1≤ti≤n). If a game can not be completed before the deadline, then you have to deduct a portion of the money from the award fee m WI,WI to the natural number, different games deducted the money is not the same. Of course, each game itself is simple enough to ensure that each contestant can be completed within a period of time and must start all the time. The host just wants to test how each contestant arranges to organize their own game order. As a contestant, Xiao Wei wants to win the championship and, of course, wants to win the most money! Note: The competition will never lose money to the contestants.

Input

Total 4 lines:
The 1th act m, which represents the first prize to each contestant's money;
The 2nd Act n, indicates that there are n small games;
The 3rd line has n number, respectively indicates the game 1 to n the stipulation completion period;
The 4th line has n number, respectively, the game 1 to n can not be completed before the specified period of deduction.

Output

Just 1 lines, that Xiao Wei can win the most money.

Sample input
1000074 2 4 3 1 4 670 60 50 40 30 20 10
Sample output
9950

Analysis: First order by time, then for example now to T time, then in this period of either can be completed, or take the largest T, Priority queue simulation can be;
Code:
#include <bits/stdc++.h>#defineFi first#defineSe Second#definell Long Longusing namespacestd;Const intmaxn=1e4+Ten;intN,m;priority_queue<int,vector<int>,greater<int> >A;pair<int,int>b[maxn];ll ans;intMain () {inti,j,k,t; scanf ("%lld",&ans); scanf ("%d",&N);  for(intI=0; i<n;i++) scanf ("%d",&b[i].fi);  for(intI=0; i<n;i++) scanf ("%d", &b[i].se), ans-=b[i].se; Sort (b,b+N);  for(intI=0; i<n;i++) {A.push (b[i].se); if(A.size () >b[i].fi) A.pop (); }     while(!a.empty ()) ans+=a.top (), A.pop (); printf ("%lld\n", ans); //System ("pause");    return 0;}



Intellectual big Surf (riddle)

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.