-
Notifications
You must be signed in to change notification settings - Fork 0
/
4B.cpp
44 lines (42 loc) · 883 Bytes
/
4B.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll n,m;
cin >> n >> m;
ll total = 0;
ll rem = 0;
ll a[n][2];
for(int i = 0 ; i < n ; i ++)
{
cin >> a[i][0] >> a[i][1];
total += a[i][0];
rem += a[i][1] - a[i][0];
}
if( m < total || m > total + rem)
cout << "NO" << endl;
else
{
cout << "YES" <<endl;
m -= total;
for(int i = 0 ; i < n ; i ++)
{
ll t = a[i][0];
if( m > 0)
{
if( a[i][1] - a[i][0] < m)
{
t = a[i][1];
m -= (a[i][1] - a[i][0]);
}
else
{
t += m;
m = 0;
}
}
cout << t << " ";
}
}
}