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
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll t;
int n, m;
cin >> t >> n;
vector<int> a, b;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
a.push_back(tmp);
}
cin >> m;
for (int i = 0; i < m; i++) {
int tmp;
cin >> tmp;
b.push_back(tmp);
}
vector<ll> resA, resB;
//모든 부분합을 구한다.
for (int i = 0; i < n; i++) {
ll tmp = a[i];
resA.push_back(tmp);
for (int j = i+1; j < n; j++) {
tmp += a[j];
resA.push_back(tmp);
}
}
for (int i = 0; i < m; i++) {
ll tmp = b[i];
resB.push_back(tmp);
for (int j = i+1; j < m; j++) {
tmp += b[j];
resB.push_back(tmp);
}
}
sort(resB.begin(), resB.end());
// cout << "debug A ";
// for (int i = 0; i < resA.size(); i++) cout << resA[i] << ' ';
// cout << '\n';
// cout << "debug B ";
// for (int i = 0; i < resB.size(); i++) cout << resB[i] << ' ';
ll ans = 0;
for (int i = 0; i < resA.size(); i++) {
ll diff = t - resA[i]; //이 차이만큼을 B가 채우면 ok
vector<ll> ::iterator up = upper_bound(resB.begin(), resB.end(), diff);
vector<ll> ::iterator lo = lower_bound(resB.begin(), resB.end(), diff);
ans += up-lo;
}
cout << ans << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
BOJ/C++