Submission #25547

#TimeUsernameProblemLanguageResultExecution timeMemory
25547youngyojun스트랩 (JOI14_straps)C++11
100 / 100
39 ms21672 KiB
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <vector> #include <stack> #include <deque> #include <queue> #include <set> #include <map> #include <unordered_map> #include <bitset> #include <string> #define pb push_back #define sz(V) ((int)(V).size()) #define allv(V) ((V).begin()),((V).end()) #define befv(V) ((V)[(sz(V)-2)]) #define sorv(V) sort(allv(V)) #define revv(V) reverse(allv(V)) #define univ(V) (V).erase(unique(allv(V)),(V).end()) #define clv(V) (V).clear() #define upmin(a,b) (a)=min((a),(b)) #define upmax(a,b) (a)=max((a),(b)) #define rb(x) ((x)&(-(x))) #define INF (1100000099) #define INFLL (1100000000000000099ll) #define MOD (1000000007) #define MAXN (2005) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, ll> pil; typedef pair<ll, int> pli; int d[MAXN][MAXN]; bool chk[MAXN][MAXN]; int A[MAXN], B[MAXN], P[MAXN]; int N, Ans; int main() { for(int i = 0; i < MAXN; i++) fill(d[i], d[i]+MAXN, -INF); scanf("%d", &N); for(int i = 1; i <= N; i++) scanf("%d%d", &A[i], &B[i]); for(int i = 1; i <= N; i++) A[i]--; for(int i = 1; i <= N; i++) P[i] = i; sort(P+1, P+N+1, [&](const int& a, const int& b) -> bool { return A[a] > A[b]; }); d[0][1] = 0; chk[0][1] = true; for(int i = 1; i <= N; i++) { for(int j = 1; j <= N; j++) { if(!chk[i-1][j]) continue; upmax(d[i][min(N, j+A[P[i]])], d[i-1][j] + B[P[i]]); chk[i][min(N, j+A[P[i]])] = true; } for(int j = 0; j <= N; j++) { if(!chk[i-1][j]) continue; chk[i][j] = true; upmax(d[i][j], d[i-1][j]); } } for(int i = 0; i <= N; i++) upmax(Ans, d[N][i]); printf("%d\n", Ans); return 0; }

Compilation message (stderr)

straps.cpp: In function 'int main()':
straps.cpp:46:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
straps.cpp:47:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%d%d", &A[i], &B[i]);
                                                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...