-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF_1461C.cpp
61 lines (54 loc) · 988 Bytes
/
CF_1461C.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
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <cstdlib>
#include <list>
#include <iomanip>
#define ll long long
#define ld long double
#define MOD 1000000007
#define INF LLONG_MAX
using namespace std;
int main()
{
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int N, M;
cin >> N >> M;
vector<int> P(N + 1);
for (int i = 1; i <= N; i++) {
cin >> P[i];
}
int idxBackSorted = N+1;
int pNum = N;
for (int i = N; i >= 1; i--) {
if (P[i] != pNum) break;
else {
pNum--;
idxBackSorted = i;
}
}
ld ans = 0;
for (int i = 0; i < M; i++) {
int r;
ld p;
cin >> r >> p;
if (r < idxBackSorted - 1) continue;
ans += (1 - ans) * p;
}
if (idxBackSorted == 1) {
cout << 1 << endl;
}
else {
cout << ans << endl;
}
}
}