#include <iostream>
#include <vector>
using namespace std;
int pos_sum(vector<int> &v){
int res = 0;
for(auto &i : v)
res += i * (i > 0);
return res;
}
int min_max_mult(vector<int> &v){
int res = 1;
pair<int,int> mn,mx;
mn = {v[0],0};
mx = mn;
for(int i = 1; i < v.size(); i++){
if(v[i] > mx.first){
mx.first = v[i];
mx.second = i;
if(v[i] < mn.first){
mn.first = v[i];
mn.second = i;
int st = min(mn.second, mx.second), fn = max(mn.second,mx.second);
for(int i = st + 1; i < fn; i++)
res *= v[i];
int main(){
int n;
cin >> n;
vector<int> a(n);
for(auto &i : a) cin >> i;
cout << pos_sum(a) << " " << min_max_mult(a);
int main()
{
int s = 0, l = 1, n;
vector <int> v(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
if (v[i] > 0)
s += v[i];
int imn = 0, imx = 0;
if (v[i] < v[imn])
imn = i;
if (v[i] > v[imx])
imx = i;
if (imn > imx)
swap (v[imn], v[imx]);
for (int i = imn; i < imx; i++)
l *= v[i];
cout << s << " " << l;
return 0;
Объяснение:
#include <iostream>
#include <vector>
using namespace std;
int pos_sum(vector<int> &v){
int res = 0;
for(auto &i : v)
res += i * (i > 0);
return res;
}
int min_max_mult(vector<int> &v){
int res = 1;
pair<int,int> mn,mx;
mn = {v[0],0};
mx = mn;
for(int i = 1; i < v.size(); i++){
if(v[i] > mx.first){
mx.first = v[i];
mx.second = i;
}
if(v[i] < mn.first){
mn.first = v[i];
mn.second = i;
}
}
int st = min(mn.second, mx.second), fn = max(mn.second,mx.second);
for(int i = st + 1; i < fn; i++)
res *= v[i];
return res;
}
int main(){
int n;
cin >> n;
vector<int> a(n);
for(auto &i : a) cin >> i;
cout << pos_sum(a) << " " << min_max_mult(a);
}
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int s = 0, l = 1, n;
cin >> n;
vector <int> v(n);
for (int i = 0; i < n; ++i)
{
cin >> v[i];
if (v[i] > 0)
{
s += v[i];
}
}
int imn = 0, imx = 0;
for (int i = 0; i < n; ++i)
{
if (v[i] < v[imn])
{
imn = i;
}
if (v[i] > v[imx])
{
imx = i;
}
}
if (imn > imx)
{
swap (v[imn], v[imx]);
}
for (int i = imn; i < imx; i++)
{
if (v[i] > 0)
{
l *= v[i];
}
}
cout << s << " " << l;
return 0;
}
Объяснение: