Submission #404998

#TimeUsernameProblemLanguageResultExecution timeMemory
404998nicolaalexandraA Difficult(y) Choice (BOI21_books)C++14
0 / 100
14 ms252 KiB
#include<bits/stdc++.h> #include"books.h" #define DIM 100010 using namespace std; int n,k,s,i; long long a; long long v[DIM],d[DIM]; void solve(int n, int k, long long a, int s) { int i; long long sum = 0; for (i=1;i<=k;i++){ d[i] = skim(i); sum += d[i]; } if (sum > 2*a){ impossible(); return; } vector <int> ans; if (sum >= a){ for (i=1;i<=k;i++) ans.push_back(i); answer(ans); return; } sum -= d[k]; int st = k, dr = n, poz = n+1; long long val; while (st <= dr){ int mid = (st + dr) >> 1; long long nr = skim (mid); if (nr >= a){ poz = mid, val = nr; dr = mid-1; } else st = mid+1; } if (poz <= n && sum + val >= a && sum + val <= 2*a){ ans.push_back(poz); for (i=1;i<k;i++) ans.push_back(i); } else { sum += d[k]; int st = 1, dr = k+1; while (sum < a){ sum -= d[st], d[dr] = skim(dr); sum += d[dr]; st++, dr++; } if (sum < a || sum > 2*a){ impossible(); return; } for (i=st;i<dr;i++) ans.push_back(i); } sort (ans.begin(),ans.end()); answer(ans); }

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:44:25: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |     if (poz <= n && sum + val >= a && sum + val <= 2*a){
      |                     ~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...