File tree Expand file tree Collapse file tree 3 files changed +178
-0
lines changed Expand file tree Collapse file tree 3 files changed +178
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+ #include < iomanip>
4
+ #include < vector>
5
+ #include < string>
6
+ #include < algorithm>
7
+ #include < unordered_map>
8
+ #include < cmath>
9
+ #include < stack>
10
+ #include < cstdio>
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ int main () {
19
+ int t;
20
+ cin>>t;
21
+ while (t--){
22
+ vector<int > a;
23
+ string s;
24
+ cin>>s;
25
+ int ss;
26
+ cin>>ss;
27
+ int n=size (s);
28
+ for (int i=0 ;i<n;i++){
29
+ a.push_back (s[i]-' 0' );
30
+ }
31
+ int psum=0 ;
32
+ int pri=0 ;
33
+ for (int i=0 ;i<n;i++){
34
+ psum+=a[i];
35
+ pri=i;
36
+ if (psum>=ss){break ;}
37
+ }
38
+
39
+ if (pri>=n-1 &&psum<=ss)cout<<0 <<endl;
40
+ else if (pri==n-1 &&psum==ss){cout<<0 <<endl;
41
+
42
+ }
43
+ else {
44
+ bool su=false ;
45
+ if (psum==ss){
46
+ int w=pri+1 ;
47
+ while (a[w]==0 &&w<n)w++;
48
+ if (w==n){
49
+ su=true ;
50
+ cout<<0 <<endl;
51
+ }
52
+ }
53
+ if (!su){
54
+ int u=n-1 ;
55
+ while (a[u]==0 )u--;
56
+
57
+ while (a[pri]==9 )pri++;
58
+ for (int i=pri;i<u;i++)cout<<9 -a[i];
59
+ cout<<10 -a[u];
60
+ for (int i=0 ;i<n-u-1 ;i++)cout<<0 ;
61
+ cout<<endl;
62
+ }
63
+ }
64
+
65
+ }
66
+
67
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+ #include < vector>
4
+ int main (){
5
+ int t;
6
+ cin>>t;
7
+ for (int tt=0 ;tt<t;tt++){
8
+ int n;
9
+ cin>>n;
10
+ vector<int > a (n);
11
+ for (int i=0 ;i<n;i++)cin>>a[i];
12
+ // int maxcount=0;
13
+ int trend;
14
+ int j;
15
+ for (j=n-1 ;j>0 ;j--){
16
+ if (a[j]>a[j-1 ]){
17
+ trend=0 ;
18
+ break ;
19
+ }
20
+ else if (a[j]<a[j-1 ]){
21
+ trend=1 ;
22
+ break ;
23
+ }
24
+
25
+
26
+ }
27
+ if (j==0 ){cout<<0 <<endl;}
28
+
29
+ else {
30
+ int ans;
31
+
32
+ if (trend==0 ){
33
+ bool broke=false ;
34
+ for (int k=j-1 ;k>0 ;k--){
35
+ if (a[k]<a[k-1 ]){
36
+ ans=k;
37
+ broke=true ;
38
+ break ;
39
+ }
40
+
41
+ }
42
+ if (!broke){ans=0 ;}
43
+ cout<<ans<<endl;
44
+ }
45
+ else if (trend==1 ){
46
+ bool switched=false ;
47
+ bool broke=false ;
48
+ for (int k=j-1 ;k>0 ;k--){
49
+ if (!switched){
50
+ if (a[k]>a[k-1 ]){switched=true ;}
51
+ }
52
+ else {
53
+ if (a[k]<a[k-1 ]){
54
+ ans=k;
55
+ broke=true ;
56
+
57
+ }
58
+ if (broke){break ;}
59
+ }
60
+ }
61
+ if (!switched||!broke){ans=0 ;}
62
+ cout<<ans<<endl;
63
+ }
64
+
65
+ }
66
+
67
+ }
68
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+ #include < iomanip>
4
+ #include < vector>
5
+ #include < string>
6
+ #include < algorithm>
7
+ #include < unordered_map>
8
+ #include < cmath>
9
+ #include < stack>
10
+ #include < cstdio>
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ int main () {
19
+ int t;
20
+ cin>>t;
21
+ while (t--){
22
+ long long int a,b,x,y,n;
23
+ cin>>a>>b>>x>>y>>n;
24
+ if (a-x+b-y<=n)cout<<x*y<<endl;
25
+ else {
26
+ if (a-x<n&&b-y<n){
27
+ cout<<min ((a-(n-(b-y)))*y,(b-(n-(a-x)))*x)<<endl;
28
+ }
29
+ else if (a-x>=n&&b-y<n){
30
+ cout<<min ((y*(a-(n-(b-y)))),(a-n)*b)<<endl;
31
+
32
+ }
33
+ else if (a-x<n&&b-y>=n){
34
+ cout<<min (x*(b-(n-(a-x))),a*(b-n))<<endl;
35
+ }
36
+ else if (a-x>=n&&b-y>=n){
37
+ cout<<min (a*(b-n),b*(a-n))<<endl;
38
+ }
39
+ }
40
+
41
+ }
42
+
43
+ }
You can’t perform that action at this time.
0 commit comments