Const n=10; var a:array[1..n] of integer; i,s,min:integer; begin writeln('Исходный массив:'); for i:=1 to n do begin a[i]:=random(21)-10; write(a[i]:4); end; writeln; s:=0; min:=a[1]; for i:=1 to n do begin if a[i]>0 then s:=s+a[i]; if a[i]<min then min:=a[i]; end; writeln('s = ',s,' min = ',min); for i:=1 to n do if a[i]>0 then a[i]:=s else if a[i]<0 then a[i]:=a[i]-min; writeln('Измененный массив:'); for i:=1 to n do write(a[i]:4); writeln; end.
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cassert>
#include <random>
#pragma GCC target("avx,avx2,sse3,ssse3,sse4.1,sse4.2,tune=native")
#pragma GCC optimize(3)
#pragma GCC optimize("O3")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
const int N = 3e5 + 100, A = 2e5 + 100, MOD = 1e9 + 7, INF = 1e18;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void solve();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
solve();
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void solve() {
int n;
cin >> n;
vector < int > a;
a.resize(n);
mt19937 mt(time(0));
for (int i = 0; i < n; i++) {
a[i] = mt();
}
int mx = -INF;
for (int i = 0; i < n / 2; i++) {
mx = max(mx, a[i]);
}
for (int i = 0; i < n / 2; i++) {
a[i] -= mx;
}
for (int i = n / 2 - 1; i >= 0; i--) {
cout << a[i] << " ";
}
cout << '\n';
mx = -INF;
for (int i = n / 2; i < n; i++) {
mx = max(mx, a[i]);
}
for (int i = n / 2; i < n; i++) {
a[i] -= mx;
cout << a[i] << " ";
}
cout << '\n';
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
var a:array[1..n] of integer;
i,s,min:integer;
begin
writeln('Исходный массив:');
for i:=1 to n do
begin
a[i]:=random(21)-10;
write(a[i]:4);
end;
writeln;
s:=0;
min:=a[1];
for i:=1 to n do
begin
if a[i]>0 then s:=s+a[i];
if a[i]<min then min:=a[i];
end;
writeln('s = ',s,' min = ',min);
for i:=1 to n do
if a[i]>0 then a[i]:=s
else if a[i]<0 then a[i]:=a[i]-min;
writeln('Измененный массив:');
for i:=1 to n do write(a[i]:4);
writeln;
end.
Пример:
Исходный массив:
9 -3 -5 7 1 5 -6 9 -8 7
s = 38 min = -8
Измененный массив:
38 5 3 38 38 38 2 38 0 38