Submission #942466

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
9424662024-03-10 17:03:21SunbaeKnapsack (NOI18_knapsack)C++17
100 / 100
71 ms4568 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[2005];
array<int,3> Op[100005];
vector<pair<int,int>> vec[2005];
const ll inf = 1e15;
signed main(){
int S, n; scanf("%d %d", &S, &n);
vector<int>C;
for(int i = 0, Vi, Wi, Ki; i<n; ++i){
scanf("%d %d %d", &Vi, &Wi, &Ki);
Op[i] = {Vi, Wi, Ki};
C.push_back(Wi);
}
C.push_back(-1);
sort(C.begin(), C.end());
C.resize(unique(C.begin(), C.end()) - C.begin());
for(int i = 0; i<n; ++i){
int Vi = Op[i][0], Wi = Op[i][1], Ki = Op[i][2];
vec[upper_bound(C.begin(), C.end(), Wi) - C.begin() - 1].emplace_back(Vi, Ki);
}
int m = C.size();
for(int j = 1; j<=S; ++j) dp[j] = -inf;
dp[0] = 0;
for(int i = 1; i<m; ++i){
sort(vec[i].begin(), vec[i].end(), greater<pair<int,int>>());
ll w = C[i];
for(int j = S; j>=0; --j){
bool br = false;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:46:5: warning: unused variable 'ans' [-Wunused-variable]
   46 |  ll ans = -inf;
      |     ^~~
knapsack.cpp:9:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  int S, n; scanf("%d %d", &S, &n);
      |            ~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("%d %d %d", &Vi, &Wi, &Ki);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...