-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path59614940.cpp
45 lines (45 loc) · 824 Bytes
/
59614940.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,v;
cin>>n>>v;
int arr[3010];
fill(arr,arr+3010,0);
for(int i=0;i<n;i++)
{
int a,b;
//cin>>a>>b;
scanf("%d %d",&a ,&b);
arr[a]+=b;
//cout<<"arr[2]="<<arr[2]<<endl;
}
int sum =0;
/*for(int i=0;i<n+5;i++)
cout<<arr[i]<<" ";
cout<<endl;*/
for(int i=1;i<3002;i++)
{
int today=v;
today-=arr[i-1];
if(today<=0)
{
sum+=v;
continue;
}
if(today>=arr[i])
{
today-=arr[i];
sum+=v-today;
arr[i]=0;
}
else
{
arr[i]-=today;
sum+=v;
}
//cout<<sum<<endl;
}
cout<<sum<<endl;
return 0;
}