B - Checkout Assistant

Crawling in process...Crawling failedTime Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

​Submit​​​ ​​​Status​​​ ​​​Practice​​​ ​​​CodeForces 19B​

Description

Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti

Input

The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.

Output

Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.

Sample Input

Input

42 100 201 51 3

Output

8

Input

30 10 100 100

Output

111

#include<iostream>#include<algorithm>#include<cstring>#include<map>using namespace std;const long long oo=1e18;const int mm=2005;long long f[mm];int m,x;long long y,z;int main(){  while(cin>>m)  {    f[0]=0;    for(int i=1;i<mm;i++)      f[i]=oo;    for(int i=0;i<m;i++)    {cin>>x>>y;      int mid;      for(int j=m;j>=0;j--)      {        if(j+x+1<m)mid=j+x+1;///时间大于m时，他可以偷所有物品因此只需到m就行        else mid=m;        if(f[j]+y<f[mid])///更新值          f[mid]=f[j]+y;      }    }    cout<<f[m]<<"\n";  }}