-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC. Polycarpus' Dice - Codeforces Round 298 (Div. 2).cpp
75 lines (68 loc) · 1.9 KB
/
C. Polycarpus' Dice - Codeforces Round 298 (Div. 2).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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ); //(will neglect the c's stdio.h property of doing inline flushing with every line of code)
//std::ios_base::sync_with_stdio(false); // (removes the interoperability that happens between C's stdio.h and iostream )
#include <iostream>
//#include<numeric>
//#include<vector>
#include<cmath>
//#include<stack>
//#include <iomanip>
//#include <vector>
#include<bits/stdc++.h>
//#include <bitset>
////#include<iomanip>
//#include <algorithm>
//#include<queue>
////#include<deque>
////#include<numeric>
//#include<set>
//#include<unordered_set>
//#include<map>
////#include<fstream>
//#include<sstream>
////#include <thread>
////#include <chrono>
//#include<cstring>
//#include<string>
//#include <unordered_map>
////#include <thread>
////#include<limits>+++
using namespace std;
int main(){
int n;
long long a;
cin>>n>>a;
long long spareUP =0;
long long spareDown =0;
vector<int> data;
vector<int> possibleSolution(n,1);
long long aTemp =a-n;
for(int i=0;i<n;++i){
int temp;
cin>>temp;
data.push_back(temp);
long long temprem =temp-1;
if((aTemp-temprem) >=0){
possibleSolution[i] = temp;
aTemp-=temprem;
}
else if (aTemp){
possibleSolution[i]+=aTemp;
aTemp=0;
}
}
for(int i =0;i<n ;++i ){
spareUP+=data[i] - possibleSolution[i];
spareDown += possibleSolution[i] -1;
}
long long templong=0;
for(int i=0;i<n;++i){
int res=0;
templong = spareUP -(data[i]-possibleSolution[i]);
long long coverup = templong - (possibleSolution[i] - 1);
if (coverup<0) res+=abs(coverup);
templong = spareDown - (possibleSolution[i] -1);
long long coverdown = templong - (data[i] - possibleSolution[i]);
if(coverdown<0) res+=abs(coverdown);
cout<<res<<' ';
}
}