Codeforces Round #278 (Div. 1)

Source: Internet
Author: User

A

A Monster is attacking the cyberland!

Master Yang, a braver, is going to beat the monster. Yang and the monster each has 3 attributes:hitpoints (HP), Offensive power (ATK) and defensive Power (DEF).

During The battle, every second the monster ' s HP decrease By  Max (0, ATK Y - DEF M ), while Yang ' s HP decreases By Max (0, ATK M - DEF y ), where Index  Y  denotes Master Yang and Index  M  denotes monster. Both decreases happen simultaneously Once monster ' S  HP ≤0 and the same time Ma Ster Yang ' s  HP > 0, Master Yang wins.

Master Yang can buy attributes from the magic Shop of Cyberland: H bitcoins per HP, a bitcoins per ATK, and D bitcoins per DEF.

Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.

Input

The first line contains three integers HPy, ATKy, DEF Y, separated by a space, denoting the initial HP, ATK and DEF of Mast Er Yang.

The second line contains three integers HPm, ATKm, DEF M, separated by a space, denoting the HP, ATK and def of the monster.

The third line contains three integers h, a, D, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF.

All numbers in input is integer and lie between 1 and inclusively.

Output

The only output line should contain a integer, denoting the minimum bitcoins Master Yang should spend in order to win.

Violent attack

#include <iostream>#include<string.h>#include<stdio.h>using namespacestd;Const intMaxa = -;intDp[maxa][maxa];intMain () {intx, y, Z; intx1, Y1, Z1; intA, B, C; CIN>>x>>y>>z>>x1>>y1>>z1>>a>>b>>C; intGuanwujianxue = y-Z1; intUU =0;//Money    if(Guanwujianxue <=0) {UU= b * (-guanwujianxue +1); Guanwujianxue=1; }    intYingxiongjianxue = Max (0, Y1-z); intMina =10000000;  for(intI =guanwujianxue; i < Maxa; i++){         for(intK= Yingxiongjianxue; K >=0; k--){            intsum = (I-guanwujianxue) *b + (yingxiongjianxue-k) *C; intn = x1/i; if(x1% i! =0) n++; if(k * N <x) Mina=min (mina, sum); Else{mina= min (mina, sum + (k*n+1-X) *a); } }} cout<<mina+uu<<Endl;}
View Code

Alexandra have a paper strip with n numbers on it. Let's call them ai from left to right.

Now Alexandra wants-to-split it into some pieces (possibly 1). For each piece of strip, it must satisfy:

    • Each piece should contain at least l numbers.
    • The difference between the maximal and the minimal number on the piece should is at most s.

Alexandra to find the minimal number of pieces meeting the condition above.

Input

The first line contains three space-separated integers n, s, l (1≤ n ≤10 5, 0≤ s ≤10 9, 1≤ l ≤105).

The second line contains n integers ai separated by spaces ( -9≤ a< /c8>i ≤109).

Output

Output the minimal number of strip pieces.

If There is no ways to split the strip, Output-1.

The idea is linear, see a brilliant solution

#include <stdio.h>#include<string.h>#include<iostream>#include<Set>using namespacestd;Const intMaxa =100005;intDp[maxa];intN, S, L;multiset<int>St, RT;intA[maxa];intMain () {scanf ("%d%d%d", &n, &s, &l);  for(inti =0; I < n; i++) {scanf ("%d", &A[i]); }     for(inti =0, j =0; I < n; i++) {St.insert (a[i]);  while(*st.rbegin ()-*st.begin () >s)            {St.erase (St.find (A[j])); if(I-j >=l) rt.erase (Rt.find (dp[j-1])); J++; }        if(i-j+1>=l) Rt.insert (dp[i-l]); if(Rt.begin () = = Rt.end ()) dp[i] =Maxa; ElseDp[i] = *rt.begin () +1; }    if(dp[n-1] >= Maxa) dp[n-1] = -1; cout<<dp[n-1]<<Endl;}
View Code

Codeforces Round #278 (Div. 1)

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.