Educational Codeforces Round 52 (Rated for Div. 2)

A.

A. Vasya and Chocolate
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a special offer in Vasya's favourite supermarket: if the customer buys aa chocolate bars, he or she may take bb additional bars for free. This special offer can be used any number of times.

Vasya currently has ss roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs cc roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!

Input

The first line contains one integer tt (1t1001≤t≤100) — the number of testcases.

Each of the next tt lines contains four integers s,a,b,c (1s,a,b,c109)s,a,b,c (1≤s,a,b,c≤109) — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.

Output

Print tt lines. ii-th line should contain the maximum possible number of chocolate bars Vasya can get in ii-th test.

Example
input
Copy
2
10 3 1 1
1000000000 1 1000000000 1
output
Copy
13
1000000001000000000
Note

In the first test of the example Vasya can buy 99 bars, get 33 for free, buy another bar, and so he will get 1313 bars.

In the second test Vasya buys 10000000001000000000 bars and gets 10000000000000000001000000000000000000 for free. So he has 10000000010000000001000000001000000000 bars.

 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     long long t,s,a,b,c;
 9     scanf("%lld",&t);
10     while(t--){
11         scanf("%lld %lld %lld %lld",&s,&a,&b,&c);
12         long long temp=a*c;
13         if(s<temp){
14             printf("%lld\n",s/c);
15         }else{
16             long long cou=(s/temp)*(a+b)+(s%temp)/c;
17             printf("%lld\n",cou);
18         }
19     }
20     return 0;
21 }

B.

B. Vasya and Isolated Vertices
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has got an undirected graph consisting of nn vertices and mm edges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edges are a pair of edges such that they connect the same pair of vertices. Since the graph is undirected, the pair of edges (1,2)(1,2) and (2,1)(2,1) is considered to be multiple edges. Isolated vertex of the graph is a vertex such that there is no edge connecting this vertex to any other vertex.

Vasya wants to know the minimum and maximum possible number of isolated vertices in an undirected graph consisting of nn vertices and mm edges.

Input

The only line contains two integers nn and m (1n105,0mn(n1)2)m (1≤n≤105,0≤m≤n(n−1)2).

It is guaranteed that there exists a graph without any self-loops or multiple edges with such number of vertices and edges.

Output

In the only line print two numbers minmin and maxmax — the minimum and maximum number of isolated vertices, respectively.

Examples
input
Copy
4 2
output
Copy
0 1
input
Copy
3 1
output
Copy
1 1
Note

In the first example it is possible to construct a graph with 00 isolated vertices: for example, it should contain edges (1,2)(1,2) and (3,4)(3,4). To get one isolated vertex, we may construct a graph with edges (1,2)(1,2) and (1,3)(1,3).

In the second example the graph will always contain exactly one isolated vertex.

wrong到结束......

还是不对

 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 typedef long long ll;
 7 
 8 ll cc[100005];
 9 
10 int main()
11 {
12     ll n,m;
13     for(ll i=1;i<=100004;i++){
14         cc[i]=i*(i-1)/2;
15     }
16     while(~scanf("%lld %lld",&n,&m)){
17         ll minn,maxx;
18         if(n==1){
19             printf("1 1\n");
20             continue;
21         }
22         if(n==0){
23             printf("0 0\n");
24             continue;
25         }
26         if(m==0){
27             printf("%lld %lld\n",n,n);
28             continue;
29         }
30         if(m*2>=n){
31             minn=0;
32             if(m>cc[n-1]){
33                 maxx=0;
34             }else{
35                 for(int i=1;i<=99999;i++){
36                     if(m>cc[i]&&m<=cc[i+1]){
37                         maxx=n-(i+1);
38                         break;
39                     }
40                 }
41 
42             }
43         }else{
44             minn=n-2*m;
45             maxx=n-m-1;
46         }
47         printf("%lld %lld\n",minn,maxx);
48     }
49     return 0;
50 }

 

 

 

 

 

 

 

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务