#include <iostream>
#include <queue>
using namespace std;
int main()
{
long long n, t, k;
cin >> n >> t >> k;
long long* c = new long long[k];
for (int i = 0; i < k; i++)
{
cin >> c[i];
}
auto q = priority_queue<pair<long long, pair<long long, long long>>, vector<pair<long long, pair<long long, long long>>>, std::greater<pair<long long, pair<long long, long long>>>>();
long long s = 0;
long long l = 0;
for (int i = 0; i < 100000; i++)
{
q.push(pair<long long, pair<long long, long long>>(c[0] + (i + 1 - 1) * t, pair<long long, long long>(i, 0))); // i, j
//for (int j = 0; j < k; j++)
//{
// // -1, bo |x| + |y| - 1
// //q.push(pair<long long, pair<long long, long long>>(c[j] + (i + 1 - 1) * t, pair<long long, long long>(j, (i + 1) * 4)));
// q.push(pair<long long, pair<long long, long long>>(c[j] + (i + 1 - 1) * t, pair<long long, long long>(i, j))); // i, j
//}
}
while (l < n)
{
//cout << "DODANI: " << min(n - l, (long long)q.top().second) << ' ' << q.top().first * min(n - l, (long long)q.top().second) << '\n';
//s = s + q.top().first * min(n - l, q.top().second);
s = s + q.top().first * min(n - l, (q.top().second.first + 1) * 4);
//l = l + min(n - l, (long long) q.top().second);
l = l + min(n - l, (q.top().second.first + 1) * 4);
q.push(pair<long long, pair<long long, long long>>(c[q.top().second.second + 1] + (q.top().second.first + 1 - 1) * t, pair<long long, long long>(q.top().second.first, q.top().second.second + 1)));
q.pop();
}
cout << s << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4300 KB |
Output is correct |
2 |
Execution timed out |
1050 ms |
3532 KB |
Time limit exceeded |
3 |
Execution timed out |
1046 ms |
3532 KB |
Time limit exceeded |
4 |
Correct |
102 ms |
3536 KB |
Output is correct |
5 |
Execution timed out |
1082 ms |
4812 KB |
Time limit exceeded |
6 |
Execution timed out |
1018 ms |
4300 KB |
Time limit exceeded |
7 |
Execution timed out |
1030 ms |
5068 KB |
Time limit exceeded |
8 |
Correct |
280 ms |
3532 KB |
Output is correct |
9 |
Correct |
202 ms |
3536 KB |
Output is correct |
10 |
Incorrect |
4 ms |
4304 KB |
Output isn't correct |