#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N = 1e3 + 10;
int n , a[N] , k , t , sum[N][N] , x[N];
vector <int> A , B;
bool marked[N][N];
bool check(int mid)
{
for(int i = 0 ; i < A.size() ; i++)
A[i] -= 2 * mid * t;
for(int i = 0 ; i < B.size() ; i++)
B[i] -= 2 * mid * t;
for(int i = 0 ; i <= A.size() ; i++)
{
sum[i][0] = 0;
if(i > 0)
sum[i][0] = A[i - 1] + sum[i - 1][0];
marked[i][0] = false;
for(int j = 1 ; j <= B.size() ; j++)
{
marked[i][j] = false;
sum[i][j] = sum[i][j - 1] + B[j - 1];
}
}
queue <pair<int ,int>> q;
marked[0][0] = true;
q.push(make_pair(0 , 0));
while(!q.empty())
{
auto now = q.front(); q.pop();
if(now.F != A.size() && sum[now.F + 1][now.S] <= 0 && !marked[now.F + 1][now.S])
{
marked[now.F + 1][now.S] = true;
q.push({now.F + 1 , now.S});
}
if(now.S != B.size() && sum[now.F][now.S + 1] <= 0 && !marked[now.F][now.S + 1])
{
marked[now.F][now.S + 1] = true;
q.push({now.F , now.S + 1});
}
}
for(int i = 0 ; i < A.size() ; i++)
A[i] += 2 * mid * t;
for(int i = 0 ; i < B.size() ; i++)
B[i] += 2 * mid * t;
return marked[A.size()][B.size()];
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> k >> t;
for(int i = 1 ; i <= n ; i++)
cin >> x[i];
for(int i = 1 ; i + 1 <= k ; i++)
A.push_back(x[i + 1] - x[i]);
for(int i = k ; i + 1 <= n ; i++)
B.push_back(x[i + 1] - x[i]);
reverse(A.begin() , A.end());
int low = 0 , high = 2e9 / t;
while(high - low > 1)
{
int mid = (low + high) >> 1;
if(check(mid))
high = mid;
else
low = mid;
}
cout << high << '\n';
return 0;
}
Compilation message
sparklers.cpp: In function 'bool check(long long int)':
sparklers.cpp:14:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 0 ; i < A.size() ; i++)
| ~~^~~~~~~~~~
sparklers.cpp:16:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i = 0 ; i < B.size() ; i++)
| ~~^~~~~~~~~~
sparklers.cpp:19:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i = 0 ; i <= A.size() ; i++)
| ~~^~~~~~~~~~~
sparklers.cpp:25:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int j = 1 ; j <= B.size() ; j++)
| ~~^~~~~~~~~~~
sparklers.cpp:37:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if(now.F != A.size() && sum[now.F + 1][now.S] <= 0 && !marked[now.F + 1][now.S])
| ~~~~~~^~~~~~~~~~~
sparklers.cpp:42:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(now.S != B.size() && sum[now.F][now.S + 1] <= 0 && !marked[now.F][now.S + 1])
| ~~~~~~^~~~~~~~~~~
sparklers.cpp:48:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0 ; i < A.size() ; i++)
| ~~^~~~~~~~~~
sparklers.cpp:50:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0 ; i < B.size() ; i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2520 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2520 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2520 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |