Lesson 40 of 50 beginner

Your CP Journey — What's Next!

You've built the foundation — now let's talk about the skyscraper!

Open interactive version (quiz + challenge)

Real-world analogy

This moment is like graduating and looking at the road ahead. You've built a strong foundation — you know C++, algorithms, data structures, problem-solving, and debugging. Now it's time to build the skyscraper! The road ahead is exciting: new algorithms, harder problems, real contests, and a community of millions of coders. Your journey has just begun!

What is it?

This final lesson is your graduation ceremony and roadmap! We recap everything you've learned in 40 lessons, explain the Codeforces rating system, give you a clear study plan for what to learn next, introduce the CP community, and send you off with encouragement. You've built an incredible foundation — now it's time to fly!

Real-world relevance

Competitive programming skills have launched thousands of careers. Gennady Korotkevich (tourist), the #1 CP programmer, works at a top tech company. Petr Mitrichev works at Google. Many ICPC World Finalists become tech leaders, startup founders, and researchers. The problem-solving skills you've learned are valued in every industry — from finance to medicine to space exploration!

Key points

Code example

#include <bits/stdc++.h>
using namespace std;

// Your CP template — use this for every contest!
// Customize it as you learn more tricks.

int main() {
    // Fast I/O — makes cin/cout as fast as scanf/printf
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;  // Number of test cases
    
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
        
        // === YOUR SOLUTION GOES HERE ===
        
        // Example: find min, max, sum
        int minVal = *min_element(a.begin(), a.end());
        int maxVal = *max_element(a.begin(), a.end());
        long long sum = 0;
        for (int x : a) sum += x;
        
        cout << "Min: " << minVal << "\n";
        cout << "Max: " << maxVal << "\n";
        cout << "Sum: " << sum << "\n";
        
        // Sort (O(n log n))
        sort(a.begin(), a.end());
        
        // Binary search (O(log n))
        int target = 42;
        bool found = binary_search(a.begin(), a.end(), target);
        cout << "Found 42? " << (found ? "YES" : "NO") << "\n";
    }
    
    return 0;
}

// EVERYTHING YOU'VE LEARNED:
// Lesson 1-5: Programming basics, variables, I/O, data types
// Lesson 6-10: Conditions, loops, patterns, operators
// Lesson 11-15: Functions, arrays, strings, math tricks
// Lesson 16-20: STL, vectors, pairs, sets, maps
// Lesson 21-25: Sorting, searching, two pointers, frequency counting
// Lesson 26-31: Prefix sums, greedy, basic DP ideas, problem patterns
// Lesson 32-35: Recursion, stacks, queues
// Lesson 36-39: Problem reading, solving, debugging, time complexity
// Lesson 40: YOUR JOURNEY CONTINUES!

Line-by-line walkthrough

  1. 1. ios_base::sync_with_stdio(false); cin.tie(NULL); — these two lines speed up cin and cout dramatically. Always include them in contest code! They disconnect C++ streams from C streams, removing synchronization overhead.
  2. 2. int t; cin >> t; while (t--) — the standard multiple test case pattern. Read how many test cases, then solve each one in the loop.
  3. 3. vector a(n); — create a vector of n integers. Vectors are safer and more flexible than raw arrays.
  4. 4. *min_element(a.begin(), a.end()) — a handy STL function that finds the minimum element. The * at the front dereferences the iterator to get the actual value.
  5. 5. sort(a.begin(), a.end()); — O(n log n) sorting, one of the most used operations in CP.
  6. 6. binary_search(a.begin(), a.end(), target) — returns true/false whether the target exists in a SORTED container. O(log n) — super fast!
  7. 7. This template is your starting point for every contest. Over time, you'll add more helper functions, macros, and tricks. Many top programmers have templates with hundreds of lines of pre-written code!
  8. 8. The comment block at the bottom recaps all 40 lessons — from basic programming to advanced problem-solving. Look how much you've learned!

Spot the bug

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    // Find target using binary search
    int target;
    cin >> target;
    
    bool found = binary_search(a.begin(), a.end(), target);
    cout << (found ? "YES" : "NO") << "\n";
    return 0;
}
Need a hint?
Binary search has an important prerequisite. What condition must the array satisfy for binary_search to work correctly?
Show answer
The bug is that binary_search REQUIRES the array to be SORTED, but we never sort it! Binary search works by checking the middle element and eliminating half the array — this only works if elements are in order. The fix is to add 'sort(a.begin(), a.end());' before the binary_search call. Without sorting, binary search can miss elements that are actually there, giving wrong answers. Always sort before binary searching!

Explain like I'm 5

Imagine you just learned to ride a bicycle! At first you couldn't even balance, but now you can ride around the whole neighborhood. This course was your training wheels — and now they're OFF! The road ahead has hills (harder problems), sharp turns (tricky new ideas), and beautiful views (really cool solutions). Sometimes you'll fall, and that's OK — every champion fell many times before winning. Just get back on, keep pedaling, and enjoy the ride. You're a coder now, and the world is yours to explore!

Fun fact

The International Collegiate Programming Contest (ICPC) is the oldest and most prestigious programming contest, running since 1970. Teams of 3 students share ONE computer and try to solve 10+ problems in 5 hours. The winning team typically solves 8-10 problems! Countries that dominate: Russia, China, South Korea, and Poland. Maybe YOUR team will be there one day!

Hands-on challenge

Your FINAL challenge — and it's a big one! Go to Codeforces (codeforces.com), create an account if you haven't already, and solve your first problem! Try problem 4A (Watermelon) or any problem rated 800. Use your CP template from this lesson. After solving it, find a virtual contest and try to solve the A and B problems within the time limit. You're ready. Go show the world what you can do!

More resources

Open interactive version (quiz + challenge) ← Back to course: CP Zero to Hero