【LDU】2017级个人训练赛#2

A - Fox And Two Dots

http://codeforces.com/problemset/problem/510/B

Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n × m cells, like this:

Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.

The key of this game is to find a cycle that contain dots of same color. Consider 4 blue dots on the picture forming a circle as an example. Formally, we call a sequence of dots d1, d2, ..., dk a cycle if and only if it meets the following condition:

  1. These k dots are different: if i ≠ j then di is different from dj.
  2. k is at least 4.
  3. All dots belong to the same color.
  4. For all 1 ≤ i ≤ k - 1di and di + 1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge.

Determine if there exists a cycle on the field.

Input

The first line contains two integers n and m (2 ≤ n, m ≤ 50): the number of rows and columns of the board.

Then n lines follow, each line contains a string consisting of m characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.

Output

Output "Yes" if there exists a cycle, and "No" otherwise.

Examples
input
3 4
AAAA
ABCA
AAAA
output
Yes
input
3 4
AAAA
ABCA
AADA
output
No
input
4 4
YYYR
BYBY
BBBY
BBBY
output
Yes
input
7 6
AAAAAB
ABBBAB
ABAAAB
ABABBB
ABAAAB
ABBBAB
AAAAAB
output
Yes
input
2 13
ABCDEFGHIJKLM
NOPQRSTUVWXYZ
output
No
Note

In first sample test all 'A' form a cycle.

In second sample there is no such cycle.

The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red).


#include<stdio.h>
#include<string.h>
char a[200][200];
int vis[200][200];
int n,m,flag;
int next[5][2]={{0,0},{0,1},{-1,0},{0,-1},{1,0}};
void dfs(int x,int y,int prx,int pry)
{
   int i,j,tx,ty;
   for(i=1;i<=4;i++)
     {
        tx=x+next[i][0];
        ty=y+next[i][1];
        if(tx>=0 && tx<n && ty>=0 && ty<m &&  a[tx][ty]==a[prx][pry] )
        {
             if(tx==prx  &&  ty==pry)
             {
                continue;
             }
             if(vis[tx][ty]==1)
             {
                 flag=1;
                 break;
             }
             vis[tx][ty]=1;
             dfs(tx,ty,x,y);
        }
        if(flag==1)
           break;
     }
     return ;
}
int main()
{
     int i,j;
     while(scanf("%d%d",&n,&m)!=EOF)
     {
         for(i=0;i<n;i++)
            scanf("%s",a[i]);
         memset(vis,0,sizeof(vis));
         for(i=0;i<n;i++)
         {
             for(j=0;j<m;j++)
             {
                 if(vis[i][j]==1)
                 {
                     continue;
                 }
                 flag=0;
                 vis[i][j]=1;
                 dfs(i,j,i,j);
                 if(flag==1)
                 break;
             }
             if(flag==1)
             break;
         }
          if(flag==1)
             printf("Yes\n");
          else
             printf("No\n");
     }return 0;


}

B - Saruman's Army 

https://vjudge.net/contest/202187#problem/B

Description

Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes seeing stones, known as palantirs, among the troops. Each palantir has a maximum effective range of R units, and must be carried by some troop in the army (i.e., palantirs are not allowed to “free float” in mid-air). Help Saruman take control of Middle Earth by determining the minimum number of palantirs needed for Saruman to ensure that each of his minions is within R units of some palantir.

Input

The input test file will contain multiple cases. Each test case begins with a single line containing an integer R, the maximum effective range of all palantirs (where 0 ≤ R ≤ 1000), and an integer n, the number of troops in Saruman’s army (where 1 ≤ n ≤ 1000). The next line contains n integers, indicating the positions x1, …, xn of each troop (where 0 ≤ xi ≤ 1000). The end-of-file is marked by a test case with R = n = −1.

Output

For each test case, print a single integer indicating the minimum number of palantirs needed.

Sample Input

0 3
10 20 20
10 7
70 30 1 7 15 20 50
-1 -1

Sample Output

2
4

Hint

In the first test case, Saruman may place a palantir at positions 10 and 20. Here, note that a single palantir with range 0 can cover both of the troops at position 20.

In the second test case, Saruman can place palantirs at position 7 (covering troops at 1, 7, and 15), position 20 (covering positions 20 and 30), position 50, and position 70. Here, note that palantirs must be distributed among troops and are not allowed to “free float.” Thus, Saruman cannot place a palantir at position 60 to cover the troops at positions 50 and 70.


#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
      int a[1050],b[1050],x;
      int i,r,n;
      while(~scanf("%d%d",&r,&n))
      {
           if(r==-1&&n==-1)
              return 0;
           int count=0;
           for(i=0;i<n;i++)
           {
              scanf("%d",&a[i]);
           }
           sort(a,a+n);
           int p=a[0];
           for(i=0;i<n;)
           {
                p=a[i++];

                for(;i<n&&p+r>=a[i];i++);

                p=a[i-1];     count++;

                for(;i<n&&p+r>=a[i];i++);

           }
           printf("%d\n",count);
      }
      return 0;

}

C - Spreadsheets 

http://codeforces.com/problemset/problem/1/B

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.

Input

The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .

Output

Write n lines, each line should contain a cell coordinates in the other numeration system.

Examples
input
2
R23C55
BC23
output
BC23
R23C55
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<algorithm>
#include<math.h>
using namespace std;
int judge(char a[])
{
    int i;
    int len=strlen(a);
    if(a[0]=='R')
    {
        for(i=0;i<len;i++)
        {
            if(isdigit(a[i])&&i>=1)
               continue;
            if(a[i]=='C'&&isdigit(a[i-1])&&isdigit(a[i+1]))
                return 1;
        }
    }
    return 0;

}
int main()
{

     int n,i,j;
     while(~scanf("%d",&n))
     {
        while(n--)
        {
              int n1,n2;
              char a[200];
              int  b[200]={0};
              char c[200]={'\0'};
              scanf("%s",a);
              if(judge(a))
              {
                  sscanf(a,"R%dC%d",&n1,&n2);
                  i=0;
                  while(n2>0)
                  {
                      if(n2%26==0)
                      {
                         b[i++]=26;
                         n2--;
                      }
                      else
                      {
                         b[i++]=n2%26;
                      }
                      n2/=26;
                  }

                  for(i--;i>=0;i--)
                  {
                     printf("%c",b[i]+64);
                  }
                  printf("%d\n",n1);
              }
              else
              {
                  sscanf(a,"%[A-Z]%d",c,&n2);
                  int len=strlen(c);
                  reverse(c,c+len);
                  n1=0;
                  for(i=0;i<strlen(c);i++)
                  {
                      n1+=((c[i]-'A'+1)*pow(26,i));
                  }
                  printf("R%dC%d\n",n2,n1);
              }
        }
     }
     return 0;

}


D - Find The Bone 

http://codeforces.com/problemset/problem/796/B

Zane the wizard is going to perform a magic show shuffling the cups.

There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i.

The problematic bone is initially at the position x = 1. Zane will confuse the audience by swapping the cups k times, the i-th time of which involves the cups at the positions x = ui and x = vi. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations.

Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at x = 4 and the one at x = 6, they will not be at the position x = 5 at any moment during the operation.

Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.

Input

The first line contains three integers nm, and k (2 ≤ n ≤ 1061 ≤ m ≤ n1 ≤ k ≤ 3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.

The second line contains m distinct integers h1, h2, ..., hm (1 ≤ hi ≤ n) — the positions along the x-axis where there is a hole on the table.

Each of the next k lines contains two integers ui and vi (1 ≤ ui, vi ≤ nui ≠ vi) — the positions of the cups to be swapped.

Output

Print one integer — the final position along the x-axis of the bone.

Examples
input
7 3 4
3 4 6
1 2
2 5
5 7
7 1
output
1
input
5 1 2
2
1 2
2 4
output
2
Note

In the first sample, after the operations, the bone becomes at x = 2x = 5x = 7, and x = 1, respectively.

In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.


#include<stdio.h>
int main()
{
      int x,y,vis[10000000]={0};
      int n,m,k,i,ans;
      scanf("%d%d%d",&n,&m,&k);
      for(i=0;i<m;i++)
      {
          scanf("%d",&x);
          vis[x]=1;
      }
      ans=1;
      for(i=0;i<k;i++)
      {
          scanf("%d%d",&x,&y);
          if(x==ans)
          {
              if(vis[x]!=1)
              ans=y;
          }
          else if (y==ans)
          {
             if(vis[y]!=1)
             ans=x;
          }

      }
      printf("%d\n",ans);
      return 0;

}


E - Okabe and Banana Trees 

http://codeforces.com/problemset/problem/821/B

Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.

Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + ybananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.

Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.

Okabe is sure that the answer does not exceed 1018. You can trust him.

Input

The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 10001 ≤ b ≤ 10000).

Output

Print the maximum number of bananas Okabe can get from the trees he cuts.

Examples
input
1 5
output
30
input
2 3
output
25
Note

The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.


#include<stdio.h>
#include<algorithm>
typedef long long ll;
using namespace std;
int main()
{
    ll x,y;
    ll b,m;
    scanf("%lld%lld",&m,&b);
    ll ans=0;
    for(y=0;y<=b;y++)
    {
         x=m*(b-y);
         ans=max(ans,((x*(x+1)/2*(y+1))+(y*(y+1)/2*(x+1))));
    }
    printf("%lld\n",ans);
    return 0;
}

F - Sagheer and Nubian Market 

https://vjudge.net/problem/839090/origin

On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys kitems with indices x1, x2, ..., xk, then the cost of item xj is axj + xj·k for 1 ≤ j ≤ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.

Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?

Input

The first line contains two integers n and S (1 ≤ n ≤ 105 and 1 ≤ S ≤ 109) — the number of souvenirs in the market and Sagheer's budget.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the base costs of the souvenirs.

Output

On a single line, print two integers kT — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these ksouvenirs.

Examples
input
3 11
2 3 5
output
2 11
input
4 100
1 2 5 6
output
4 54
input
1 7
7
output
0 0
Note

In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.

In the second example, he can buy all items as they will cost him [5, 10, 17, 22].

In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it.


#include<stdio.h>
#include<algorithm>
#define maxn 100055
using namespace std;
typedef long long ll;
ll s,n,a[maxn],b[maxn];
int judge(ll x)
{
     int i;
     for(i=0;i<n;i++)
     {
         b[i]=a[i]+((i+1)*x);
     }
     sort(b,b+n);
     ll sum=0;
     for(i=0;i<x;i++)
     {
        sum+=b[i];
     }
     if(sum<=s)
        return 1;
     else
        return 0;
}
int main()
{
     while(~scanf("%lld%lld",&n,&s))
     {
         int i;
          for(i=0;i<n;i++)
          {
              scanf("%lld",&a[i]);
          }
          ll left=1,right=n,mid,ans=0;
          while(left<=right)
          {
               mid=(left+right)/2;
               if(!judge(mid))
                  right=mid-1;
               if(judge(mid))
                   left=mid+1,ans=mid;
          }
          ll sum=0;
          for(i=0;i<n;i++)
          {
              b[i]=a[i]+((i+1)*ans);
          }
          sort(b,b+n);
          for(i=0;i<ans;i++)
          {
              sum+=(b[i]);
          }
          printf("%lld %lld\n",ans,sum);
     }
     return 0;

}

G - Mike and palindrome 

http://codeforces.com/problemset/problem/798/A

Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.

A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.

Input

The first and single line contains string s (1 ≤ |s| ≤ 15).

Output

Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.

Examples
input
abccaa
output
YES
input
abbcca
output
NO
input
abcda
output
YES
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 20
using namespace std;
int main()
{
      char a[N],b[N];
      int i,j,len,sum=0;
      scanf("%s",a);
      len=strlen(a);
      strncpy(b,a,sizeof(a));


      reverse(b,b+len);
      if(strcmp(a,b)==0)
      {
          if(len%2)
          {
              printf("YES\n");
              return 0;
          }
          if(len%2==0)
          {
              printf("NO\n");
              return 0;
          }
      }

      for(i=0;i<len/2;i++)
      {
          if(a[i]!=a[len-1-i])
          {
             a[i]=a[len-1-i];
             b[len-1-i]=b[i];
             sum++;
          }
      }
      if(strcmp(a,b)==0&&sum<=1)
      {
          printf("YES\n");
      }
      else
      {
           printf("NO\n");
      }
      return 0;
}
H - Beautiful Divisors 

https://vjudge.net/problem/1221716/origin


Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes.

Some examples of beautiful numbers:

  • 12 (110);
  • 1102 (610);
  • 11110002 (12010);
  • 1111100002 (49610).

More formally, the number is beautiful iff there exists some positive integer k such that the number is equal to (2k - 1) * (2k - 1).

Luba has got an integer number n, and she wants to find its greatest beautiful divisor. Help her to find it!

Input

The only line of input contains one number n (1 ≤ n ≤ 105) — the number Luba has got.

Output

Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.

Examples
input
3
output
1
input
992
output
496

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[]={1,6,28,120,496,2016,8128,32640,130816};
int main()
{
    int n,i,ans;
    scanf("%d",&n);
    for(i=0;i<9;i++)
    {
       if(n%a[i]==0)
         ans=a[i];

    }
    printf("%d\n",ans);
    return 0;
}


I - Rikka with Competition 

http://acm.hdu.edu.cn/showproblem.php?pid=6095

Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

A wrestling match will be held tomorrow.  n  players will take part in it. The  i th player’s strength point is  ai .

If there is a match between the  i th player plays and the  j th player, the result will be related to  |aiaj| . If  |aiaj|>K , the player with the higher strength point will win. Otherwise each player will have a chance to win.

The competition rules is a little strange. Each time, the referee will choose two players from all remaining players randomly and hold a match between them. The loser will be be eliminated. After  n1  matches, the last player will be the winner.

Now, Yuta shows the numbers  n,K  and the array  a  and he wants to know how many players have a chance to win the competition.

It is too difficult for Rikka. Can you help her?  
 

Input
The first line contains a number  t(1t100) , the number of the testcases. And there are no more than  2  testcases with  n>1000 .

For each testcase, the first line contains two numbers  n,K(1n105,0K<109) .

The second line contains  n  numbers  ai(1ai109) .
 

Output
For each testcase, print a single line with a single number -- the answer.
 

Sample Input
  
  
2 5 3 1 5 9 6 3 5 2 1 5 9 6 3
 

Sample Output
  
  
5 1
 

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define N 100050
using namespace std;
typedef long long ll;
int main()
{
    ll a[N],K;
    int n,ans,t,i,cnt;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%lld",&n,&K);
        for(i=0;i<n;i++)
        {
           scanf("%lld",&a[i]);
        }
        sort(a,a+n);
        ans=a[n-1];
        cnt=0;
        for(i=n-2;i>=0;i--)
        {
            if(ans-a[i]>K)
            {
                cnt++;
                break;
            }
            else
            {
                cnt++;
                ans=a[i];
            }
            if(i==0)
                cnt++;


        }
        printf("%d\n",cnt);

    }
    return 0;
}
J - Hacker, pack your bags! 

http://codeforces.com/problemset/problem/822/C

It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.

So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers liricosti — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value ri - li + 1.

At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: ri < lj or rj < li.

Help Leha to choose the necessary vouchers!

Input

The first line contains two integers n and x (2 ≤ n, x ≤ 2·105) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.

Each of the next n lines contains three integers liri and costi (1 ≤ li ≤ ri ≤ 2·105, 1 ≤ costi ≤ 109) — description of the voucher.

Output

Print a single integer — a minimal amount of money that Leha will spend, or print  - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.

Examples
input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
output
5
input
3 2
4 6 3
2 4 1
3 5 4
output
-1
Note

In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5and the total cost will be 4 + 1 = 5.

In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#define inf 1000000000000
using namespace std;
const int M = 2e5 + 10;
typedef long long ll;
struct TnT
{
    int sta, cau, flag;
    ll val;
} a[M << 1];
bool cmp(TnT x, TnT y)
{
    if(x.sta == y.sta) return x.flag > y.flag;
    return x.sta < y.sta;
}
ll dp[M];
int main()
{
    int n,i;
    ll x;
    scanf("%d%lld",&n,&x);
    int cnt=0;
    for(i=0;i<n;i++)
    {
          int l,r;
          ll c;
          scanf("%d%d%lld",&l, &r ,  &c);

          a[cnt].sta=l,a[cnt].cau=r-l+1,a[cnt].flag=1,a[cnt].val=c;

          a[++cnt].sta=r,a[cnt].cau=r-l+1,a[cnt].flag=-1,a[cnt].val=c;

          cnt++;
    }

        sort(a,a+cnt,cmp);

        for(i=0;i<M;i++)
            dp[i]=inf;

        ll ans=inf;

        for(i=0;i<cnt;i++)
        {
             if(a[i].flag==1)
             {
                 ll sum=x-a[i].cau;
                 if(sum>=0)
                 {
                     if(dp[sum]<inf)
                         ans=min(  ans,  a[i].val  +  dp[sum]   );
                 }
             }
             else
             {
                 dp[a[i].cau]=min(dp[a[i].cau],a[i].val);
             }
        }

        if(ans<inf)
           printf("%lld\n",ans);
        else
           printf("-1\n");
        return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#define inf 100000000000
typedef long long ll;
using namespace std;
struct node
{
     int l,r,c,value,cost;
}p[200005];
int cmp(node a,node b)
{
     if(a.c==b.c)
         return a.r<b.r;
     return a.c<b.c;
}
int main()
{
       int n,x,i,j,k;
       scanf("%d%d",&n,&x);
       for(i=0;i<n;i++)
       {
             scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].value);
             p[i].c=p[i].r-p[i].l+1;
             p[i].cost=p[i].value;
       }
       ll minz=inf;
       sort(p,p+n,cmp);
       for(i=0;i<n;i++)
       {
           if(i>0&&p[i].c==p[i-1].c)
               p[i].cost=min(p[i].cost,p[i-1].cost);
       }
       for(i=0;i<n;i++)
       {
            if(p[i].c>=x)
                continue;
            ll temp=x-p[i].c,v=p[i].value;
            int l=0,r=n-1,mid;
            while(l<=r)
            {
                 mid=(l+r)/2;
                 if(p[mid].c<temp)
                 {
                     l=mid+1;
                 }
                 else if (p[mid].c==temp)
                 {
                        if(p[i].l<=p[mid].r)
                           r=mid-1;
                        else
                        {
                             l=mid+1;
                             minz=min(minz,v+p[mid].cost);
                        }
                 }
                 else
                    r=mid-1;
            }
       }
       if(minz==inf)
          printf("-1\n");
       else
          printf("%lld\n",minz);
       return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值