-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-modify.cpp
More file actions
67 lines (61 loc) · 1.39 KB
/
array-modify.cpp
File metadata and controls
67 lines (61 loc) · 1.39 KB
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
ll arr[n];
for (ll i = 0; i < n; i++)
{
cin >> arr[i];
}
ll q;
cin >> q;
while (q--)
{
ll l, r, y, temp = 0;
bool flag = false;
cin >> l >> r >> y;
ll min = LLONG_MAX;
ll max = LLONG_MIN;
unordered_map<ll, int> m;
for (ll i = l - 1; i < r; i++)
{
if (arr[i] < min)
{
min = arr[i];
}
if (max < arr[i])
{
max = arr[i];
}
m[arr[i]]++;
}
// cout<<min<<" "<<max<<endl;
for (ll i = min; i <= max; i++)
{
if (m[i])
{
if (temp < y)
{
temp += i;
}
if (temp >= y)
{
cout << temp << endl;
flag = true;
break;
}
}
}
if (!flag)
{
cout << "-1" << endl;
}
}
return 0;
}
// You are given an array A of size N. Your task is to divide the elements into two parts such that the first N/2 elements are strictly increasing and next N/2 elements are non-decreasing