-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path3576.cpp
More file actions
55 lines (43 loc) · 804 Bytes
/
3576.cpp
File metadata and controls
55 lines (43 loc) · 804 Bytes
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
#include <iostream>
#include <cstdint>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int64_t N = 0;
int64_t w = 0;
int64_t d = 0;
int64_t difference = 0;
int64_t basketWithCoin = 0;
int64_t sumWeightGiven = 0;
int64_t sumWeightExpected = 0;
string input;
while(getline(cin, input))
{
stringstream stream(input);
stream >> N >> w >> d >> sumWeightGiven;
if(N < 2)
{
return 0;
}
sumWeightExpected = 0;
basketWithCoin = 0;
difference = 0;
for(int64_t i = 1; i < N; i++)
{
sumWeightExpected += (i * w);
}
difference = (sumWeightExpected - sumWeightGiven);
if(sumWeightExpected == sumWeightGiven)
{
basketWithCoin = N;
}
else
{
basketWithCoin = (difference / d);
}
cout << basketWithCoin << endl;
}
return 0;
}