CSES - Datatähti 2020 alku - Results
Submission details
Task:Mastot
Sender:caro
Submission time:2019-10-02 17:30:48 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp:9:19: error: conflicting declaration 'typedef long long int ll'
 typedef long long ll;
                   ^~
input/code.cpp:8:22: note: previous declaration as 'typedef unsigned int ll'
 typedef unsigned int ll;
                      ^~
input/code.cpp: In function 'int main()':
input/code.cpp:34:21: warning: large integer implicitly truncated to unsigned type [-Woverflow]
   ll bestCompare = -999999999999;
                     ^~~~~~~~~~~~

Code

#include <bits/stdc++.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
using namespace std;
typedef unsigned int ll;
typedef long long ll;
typedef struct{
ll strength;
ll cost;
} pole_s;
int main(){
ll d;
ll transmitter;
cin >> d;
cin >> transmitter;
pole_s *poles = (pole_s*) malloc(sizeof(pole_s) * (d - 1));
for(ll i = 0; i < d - 1; i++)
cin >> poles[i].strength;
for(ll i = 0; i < d - 1; i++)
cin >> poles[i].cost;
ll totalCoverage = transmitter;
ll totalCost = 0;
ll minPoint = 0;
while(1){
if(totalCoverage >= d) break;
ll best = 0;
ll bestCompare = -999999999999;
for(ll i = max(0, minPoint - 1); i < totalCoverage; i++) {
ll max = (ll)i + (ll)poles[i].strength + 1LL;
ll min = (ll)i - (ll)poles[i].strength + 1LL;
ll increase = min(max, d) - (ll)totalCoverage;
ll compare = increase - (ll)poles[i].cost;
if((compare >= bestCompare) && (increase > 0)) {
best = i;
bestCompare = compare;
minPoint = min;
}
}
totalCost += poles[best].cost;
totalCoverage = best + poles[best].strength + 1;
}
cout << totalCost << '\n';
}