-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrute.cpp
113 lines (109 loc) · 2.82 KB
/
brute.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <bits/stdc++.h>
using namespace std;
char op[13];
int main()
{
int n, m, i, l;
char t;
scanf("%i%i", &n, &m);
vector<int> arr(n);
for (auto &x : arr)
scanf("%i", &x);
while (m--)
{
// for (auto &x : arr)
// cout<<x<<" ";
// cout<<endl;
scanf(" %s", op);
t = op[2];
if (t != 'X')
{
scanf("%i%i", &i, &l);
if (!l)
{
if (t == 'T')
printf("0\n");
continue;
}
//INSERT
if (t == 'S')
{
vector<int> ne;
for (int x = 0; x < i; x++)
ne.push_back(arr[x]);
for (int x = 0; x < l; x++)
{
int a;
scanf("%i", &a);
ne.push_back(a);
}
for (int x = i; x < n; x++)
ne.push_back(arr[x]);
arr = ne;
n = arr.size();
continue;
}
switch(t)
{
//DELETE
case 'L':
{
vector<int> ne;
--i;
for (int x = 0; x < i; x++)
ne.push_back(arr[x]);
for (int x = i+l; x < n; x++)
ne.push_back(arr[x]);
arr = ne;
n = arr.size();
}
break;
//MAKE-SAME
case 'K':
{
int a;
scanf("%i", &a);
--i;
for (int x = 0; x < l; x++)
arr[x+i] = a;
}
break;
//REVERSE
case 'V':
{
--i;
for (int x = 0; x < l/2; x++)
swap(arr[i+x], arr[i+l-x-1]);
}
break;
//GET-SUM
case 'T':
{
--i;
long long sum = 0;
for (int x = 0; x < l; x++)
sum += arr[x+i];
cout<<sum<<"\n";
}
break;
default:
abort();
}
}
else
{
long long ma = INT_MIN;
for (int x = 0; x < n; x++)
{
for (int y = x; y < n; y++)
{
long long s = 0;
for (int u = x; u <= y; u++)
s += arr[u];
ma = max(ma, s);
}
}
cout<<ma<<"\n";
}
}
}