# The meaning of problems
Maximum value sign, a given number n, m is the maximum value, the average must remain unchanged, the demand can be achieved
# Explanations
ans=min(m,sum)
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define pii pair<int,int> 4 #define pll pair<ll,ll> 5 #define fi first 6 #define se second 7 #define pb push_back 8 using namespace std; 9 const int N=1e5+10; 10 int a[N]; 11 void solve(){ 12 int n,m; 13 cin>>n>>m; 14 int sum=0; 15 for(int i=1;i<=n;i++){ 16 cin>>a[i]; 17 sum+=a[i]; 18 } 19 if(sum>=m) 20 cout<<m<<endl; 21 else{ 22 cout<<sum<<endl; 23 } 24 } 25 int main(){ 26 int t; 27 cin>>t; 28 while(t--){ 29 solve(); 30 } 31 32 }
# The meaning of problems
A string operation may be performed is a number k (1 <= k <= n), i from 1 to n-k 1, the s [i ~ i k-1 +] all reverse +, calculated a k after the string so that the operation is lexicographically smallest, if there is more satisfied k, find the least k
# Explanations
First we have a string s,
we can express it as s1s2s3 ... sn, and we choose a k:
after the first reverse: sksk-1sk-2 ... s1sk + 1sk + 2 ... sn
position is then observed sk would not have happened it changed.
Subjected to a second reverse: sksk + 1s1 ... sk-2sk -1sk + 2 ... sksk + 1 position will not change after observing the sn.
If the third reverse: sksk + 1sk + 2 ... s2s1sk + 3 ... sksk + position 1sk + 2 does not change after re-sn observed.
......
and so on, after the end of the string is reversed, s' n-k + 1 before the characters must be sksk + 1sk + 2 ... sn
may be found by observing, s k-1 in the previous character s1s2s3 ... sk-1 will be moved to s', the latter half, but the direction uncertain.
Reversal number is n-k + 1, when an odd number of inversions is the need to reverse the last splice, the splice even number directly
The time complexity of O (N 2 )
1 #include<bits/stdc++.h> 2 using namespace std; 3 int T,n,ans; 4 string s,mn; 5 string work(int k) 6 { 7 if(k==n) 8 { 9 string res=s; 10 reverse(res.begin(),res.end()); 11 return res; 12 } 13 int t=n-k+1; 14 if(t%2==0) 15 { 16 string res=s.substr(k-1,n-k+1); 17 res+=s.substr(0,k-1); 18 return res; 19 } 20 string res=s.substr(k-1,n-k+1); 21 string tmp=s.substr(0,k-1); 22 reverse(tmp.begin(),tmp.end()); 23 res=res+tmp; 24 return res; 25 } 26 int main() 27 { 28 scanf("%d",&T); 29 while(T--) 30 { 31 scanf("%d",&n); 32 cin>>s; 33 ans=1,mn=s; 34 for(int i=2;i<=n;i++) 35 if(work(i)<mn) 36 mn=work(i),ans=i; 37 cout<<mn<<endl<<ans<<endl; 38 } 39 }
# C
# The meaning of problems
# answer
# D
# The meaning of problems
# answer
# E