Codeforces Round #128 (Div. 2) A. Two Problems

本文探讨了一场特殊Codeforces竞赛中,参赛者Valera如何通过解决两道题目来达到特定得分的可能性。竞赛设有两题,随时间推移得分递减,需判断Valera是否能在限定时间内获得目标分数。

A. Two Problems
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result.

He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for t minutes, the minutes are numbered starting from zero. The first problem had the initial cost of a points, and every minute its cost reduced by da points. The second problem had the initial cost of b points, and every minute this cost reduced by db points. Thus, as soon as the zero minute of the contest is over, the first problem will cost a - da points, and the second problem will cost b - db points. It is guaranteed that at any moment of the contest each problem has a non-negative cost.

Arkady asks you to find out whether Valera could have got exactly x points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute numbert - 1. Please note that Valera can't submit a solution exactly t minutes after the start of the contest or later.

Input

The single line of the input contains six integers x, t, a, b, da, db (0 ≤ x ≤ 600; 1 ≤ t, a, b, da, db ≤ 300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly.

It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, a - i·da ≥ 0 and b - i·db ≥ 0 for all 0 ≤ i ≤ t - 1.

Output

If Valera could have earned exactly x points at a contest, print "YES", otherwise print "NO" (without the quotes).

Sample test(s)
input
30 5 20 20 3 5
output
YES
input
10 4 100 5 5 1
output
NO
Note

In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30points.


题目大意是:有两个题,刚开始的分数分别为a和b,每晚一分钟做出这两个题分别扣除da和db分,求有没有可能在t分钟内Valera恰好得x分。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;


 int main()
 {
  int x,t,a,b,da,db,i,j,k;
  int at[305],bt[305];
  while(~scanf("%d%d%d%d%d%d",&x,&t,&a,&b,&da,&db))
   {
     memset(at,0,sizeof(at));
     memset(bt,0,sizeof(bt));
         at[0]=a;
         bt[0]=b;
      for(i=1;i<t;i++)
      {
        if(at[i-1]-da>0)
          at[i]=at[i-1]-da;
        else
         break;
      }
      int t=i;

      for(i=1;i<t;i++)
      {
        if(bt[i-1]-db>0)
          bt[i]=bt[i-1]-db;
        else
         break;
      }
      int ss=i;
      //for(i=0;i<=t;i++)
       //cout<<at[i]<<"***"<<bt[i]<<endl;
    for(i=0;i<=t;i++)
     {
          for(j=0;j<=ss;j++)
       {
           if(at[i]+bt[j]==x)
             {printf("YES\n");
              break; }
       }
       if(at[i]+bt[j]==x)
             {
              break; }
     }
     if(at[i]+bt[j]==x)
             {
              continue; }
     printf("NO\n");

   }
     return 0;
 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值