Skip to content

Commit 6403abe

Browse files
committed
🚀 25-Jun-2021
1 parent 48d1562 commit 6403abe

File tree

69 files changed

+6640
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+6640
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,?r1],?[l2,?r2],?...,?[ln,?rn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,?rn].
3+
4+
Input
5+
The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1?=?n?=?100,?0?=?P1,?P2,?P3?=?100,?1?=?T1,?T2?=?60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0?=?li?<?ri?=?1440, ri?<?li?+?1 for i?<?n), which stand for the start and the end of the i-th period of work.
6+
7+
Output
8+
Output the answer to the problem.
9+
10+
Examples
11+
inputCopy
12+
1 3 2 1 5 10
13+
0 10
14+
outputCopy
15+
30
16+
inputCopy
17+
2 8 4 2 5 10
18+
20 30
19+
50 100
20+
outputCopy
21+
570
22+
*/
23+
24+
25+
26+
27+
#include<bits/stdc++.h>
28+
using namespace std;
29+
30+
int main(){
31+
ios_base::sync_with_stdio(false);
32+
cin.tie(NULL);
33+
34+
int n, p1, p2, p3, t1, t2;
35+
cin >> n >> p1 >> p2 >> p3 >> t1 >> t2;
36+
37+
vector <pair <int, int>> v;
38+
39+
for (int i = 0; i < n; i++) {
40+
int l, r;
41+
cin >> l >> r;
42+
v.push_back({l, r});
43+
}
44+
45+
int consumption = 0;
46+
47+
for (int i = 0; i < n - 1; i++) {
48+
int start = v[i].first;
49+
int end = v[i].second;
50+
int nextStart = v[i + 1].first;
51+
52+
consumption += p1 * (end - start); // start ---> end
53+
54+
int notused = nextStart - end;
55+
56+
if (notused >= t1 + t2) {
57+
consumption += t1 * p1 + t2 * p2 + (notused - t1 - t2) * p3;
58+
} else if (notused >= t1) {
59+
consumption += t1 * p1 + (notused - t1) * p2;
60+
} else {
61+
consumption += notused * p1;
62+
}
63+
64+
}
65+
66+
consumption += p1 * (v[n-1].second - v[n-1].first); // for last element
67+
68+
cout << consumption;
69+
70+
return 0;
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Sasha is a very happy guy, that's why he is always on the move. There are n cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from 1 to n in increasing order. The distance between any two adjacent cities is equal to 1 kilometer. Since all roads in the country are directed, it's possible to reach the city y from the city x only if x<y.
3+
4+
Once Sasha decided to go on a trip around the country and to visit all n cities. He will move with the help of his car, Cheetah-2677. The tank capacity of this model is v liters, and it spends exactly 1 liter of fuel for 1 kilometer of the way. At the beginning of the journey, the tank is empty. Sasha is located in the city with the number 1 and wants to get to the city with the number n. There is a gas station in each city. In the i-th city, the price of 1 liter of fuel is i dollars. It is obvious that at any moment of time, the tank can contain at most v liters of fuel.
5+
6+
Sasha doesn't like to waste money, that's why he wants to know what is the minimum amount of money is needed to finish the trip if he can buy fuel in any city he wants. Help him to figure it out!
7+
8+
Input
9+
The first line contains two integers n and v (2=n=100, 1=v=100) — the number of cities in the country and the capacity of the tank.
10+
11+
Output
12+
Print one integer — the minimum amount of money that is needed to finish the trip.
13+
14+
Examples
15+
inputCopy
16+
4 2
17+
outputCopy
18+
4
19+
inputCopy
20+
7 6
21+
outputCopy
22+
6
23+
Note
24+
In the first example, Sasha can buy 2 liters for 2 dollars (1 dollar per liter) in the first city, drive to the second city, spend 1 liter of fuel on it, then buy 1 liter for 2 dollars in the second city and then drive to the 4-th city. Therefore, the answer is 1+1+2=4.
25+
26+
In the second example, the capacity of the tank allows to fill the tank completely in the first city, and drive to the last city without stops in other cities.
27+
28+
29+
*/
30+
31+
32+
33+
#include<bits/stdc++.h>
34+
using namespace std;
35+
36+
void solve() {
37+
int n, v;
38+
cin >> n >> v;
39+
40+
if (n - 1 <= v) {
41+
cout << n - 1 << "\n";
42+
return;
43+
}
44+
int fuel = 0, reqFuel = n - 1, cost = 0, index = 1;
45+
46+
fuel += v;
47+
cost += index * v; // first city
48+
49+
while (fuel < reqFuel) {
50+
index++; // next city
51+
fuel += 1; // consumed one litre
52+
cost += index * 1; // buying one litre
53+
}
54+
55+
cout << cost << "\n";
56+
}
57+
58+
int main(){
59+
ios_base::sync_with_stdio(false);
60+
cin.tie(NULL);
61+
62+
int t = 1;
63+
//cin >> t;
64+
65+
while (t--) solve();
66+
67+
return 0;
68+
}
69+
70+
/*
71+
#include<bits/stdc++.h>
72+
using namespace std;
73+
74+
void solve() {
75+
int n, v;
76+
cin >> n >> v;
77+
78+
if (n - 1 <= v) {
79+
cout << n - 1 << "\n";
80+
return;
81+
}
82+
83+
int cost = v - 1;
84+
int need = (n - 1) - (v - 1);
85+
86+
cost += (need * (need + 1)) / 2;
87+
88+
cout << cost << "\n";
89+
}
90+
91+
int main(){
92+
ios_base::sync_with_stdio(false);
93+
cin.tie(NULL);
94+
95+
int t = 1;
96+
//cin >> t;
97+
98+
while (t--) solve();
99+
100+
return 0;
101+
}
102+
103+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a1,a2,…,an (each ai is either 0 or 1), where ai=0 if Polycarp works during the i-th hour of the day and ai=1 if Polycarp rests during the i-th hour of the day.
3+
4+
Days go one after another endlessly and Polycarp uses the same schedule for each day.
5+
6+
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
7+
8+
Input
9+
The first line contains n (1=n=2·105) — number of hours per day.
10+
11+
The second line contains n integer numbers a1,a2,…,an (0=ai=1), where ai=0 if the i-th hour in a day is working and ai=1 if the i-th hour is resting. It is guaranteed that ai=0 for at least one i.
12+
13+
Output
14+
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
15+
16+
Examples
17+
inputCopy
18+
5
19+
1 0 1 0 1
20+
outputCopy
21+
2
22+
inputCopy
23+
6
24+
0 1 0 1 1 0
25+
outputCopy
26+
2
27+
inputCopy
28+
7
29+
1 0 1 1 1 0 1
30+
outputCopy
31+
3
32+
inputCopy
33+
3
34+
0 0 0
35+
outputCopy
36+
0
37+
Note
38+
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
39+
40+
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
41+
42+
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
43+
44+
In the fourth example, Polycarp has no rest at all.
45+
*/
46+
47+
48+
49+
50+
51+
/*
52+
#include<bits/stdc++.h>
53+
using namespace std;
54+
55+
void solve() {
56+
int n;
57+
cin >> n;
58+
59+
vector <int> v(2 * n);
60+
61+
for (int i = 0; i < n; i++) {
62+
int a;
63+
cin >> a;
64+
v[i] = a;
65+
}
66+
67+
for (int i = n; i < 2 * n; i++) v[i] = v[i - n];
68+
69+
int i = 0, res = 0, cnt = 0;
70+
71+
while (i < 2 * n) {
72+
if (v[i] == 1) {
73+
cnt++;
74+
res = max(res, cnt);
75+
} else cnt = 0;
76+
i++;
77+
}
78+
cout << res << "\n";
79+
}
80+
81+
int main(){
82+
ios_base::sync_with_stdio(false);
83+
cin.tie(NULL);
84+
85+
int t = 1;
86+
//cin >> t;
87+
88+
while (t--) solve();
89+
90+
return 0;
91+
}
92+
*/
93+
94+
95+
96+
97+
98+
#include<bits/stdc++.h>
99+
using namespace std;
100+
101+
void solve() {
102+
int n;
103+
cin >> n;
104+
105+
vector <int> v(n);
106+
107+
for (auto &x: v) cin >> x;
108+
109+
int i = 0, res = 0, cnt = 0;
110+
111+
for (int i = 0; i < 2 * n; i++) {
112+
if (v[i % n] == 1) {
113+
cnt++;
114+
res = max(res, cnt);
115+
} else cnt = 0;
116+
117+
}
118+
cout << res << "\n";
119+
}
120+
121+
int main(){
122+
ios_base::sync_with_stdio(false);
123+
cin.tie(NULL);
124+
125+
int t = 1;
126+
//cin >> t;
127+
128+
while (t--) solve();
129+
130+
return 0;
131+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
You are given two integers x and y (it is guaranteed that x>y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y?
3+
4+
Recall that a prime number is a positive integer that has exactly two positive divisors: 1 and this integer itself. The sequence of prime numbers starts with 2, 3, 5, 7, 11.
5+
6+
Your program should solve t independent test cases.
7+
8+
Input
9+
The first line contains one integer t (1=t=1000) — the number of test cases.
10+
11+
Then t lines follow, each describing a test case. Each line contains two integers x and y (1=y<x=1018).
12+
13+
Output
14+
For each test case, print YES if it is possible to choose a prime number p and subtract it any number of times from x so that x becomes equal to y. Otherwise, print NO.
15+
16+
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
17+
18+
Example
19+
inputCopy
20+
4
21+
100 98
22+
42 32
23+
1000000000000000000 1
24+
41 40
25+
outputCopy
26+
YES
27+
YES
28+
YES
29+
NO
30+
Note
31+
In the first test of the example you may choose p=2 and subtract it once.
32+
33+
In the second test of the example you may choose p=5 and subtract it twice. Note that you cannot choose p=7, subtract it, then choose p=3 and subtract it again.
34+
35+
In the third test of the example you may choose p=3 and subtract it 333333333333333333 times.
36+
37+
38+
*/
39+
40+
41+
42+
43+
#include<bits/stdc++.h>
44+
using namespace std;
45+
46+
int main(){
47+
ios_base::sync_with_stdio(false);
48+
cin.tie(NULL);
49+
50+
int t;
51+
cin >> t;
52+
53+
while (t--) {
54+
long long x, y;
55+
cin >> x >> y;
56+
57+
long long diff = x - y;
58+
59+
cout << (diff <= 1 ? "NO\n" : "YES\n");
60+
}
61+
62+
return 0;
63+
}

0 commit comments

Comments
 (0)