Nonnegative reals $x_1$, $x_2$, $\dots$, $x_n$ satisfies $x_1+x_2+\dots+x_n=n$. Let $||x||$ be the distance from $x$ to the nearest integer of $x$ (e.g. $||3.8||=0.2$, $||4.3||=0.3$). Let $y_i = x_i ||x_i||$. Find the maximum value of $\sum_{i=1}^n y_i^2$.
1. **Define the function and variables:**
   Let \( f(x) = (x \| x \|)^2 \) and \( m_i \) be the nearest integer to \( x_i \). If \( \| x_i \| = 0.5 \), let \( m_i = x_i - 0.5 \). Let \( \{ x_i \} = \text{sgn}(x_i - m_i) \times \| x_i \| \).

2. **Step 1: Smoothing the values:**
   For any two \( x_a \) and \( x_b \) such that \( -0.5 < \{ x_a \} < 0 < \{ x_b \} < 0.5 \), note that \( (x_a, x_b) \rightarrow (x_a - \varepsilon, x_b + \varepsilon) \) increases the sum of \( f(x_a) + f(x_b) \). We repeat this until one of \( \{ x_a \}, \{ x_b \} \) is equal to 0.5. Henceforth, we may assume \( \{ x_i \} \) are all positive or all negative with none or some equal to 0.5.

3. **Step 2: Rearranging the integer parts:**
   Suppose \( \| x_a \| \le \| x_b \| \). If \( m_a > m_b \), then note:
   \[
   f(x_a - m_a + m_b) + f(x_b + m_a - m_b) = (x_a - m_a + m_b)^2 \| x_a \|^2 + (x_b + m_a - m_b)^2 \| x_b \|^2 \ge (x_a \| x_a \|)^2 + (x_b \| x_b \|)^2 = f(x_a) + f(x_b)
   \]
   where the inequality holds by Rearrangement. So, we shift \( x_a \) and \( x_b \) accordingly. Repeating this across all possible pairs \( (x_a, x_b) \) arranges the \( x_i \) in the same order of \( \| x_i \| \).

4. **Step 3: Adjusting the fractional parts:**
   Consider any \( x_a, x_b \) such that \( 0.5 > \| x_a \| \ge \| x_b \| \). We shift \( x_a \) and \( x_b \) such that \( \| x_a \| \) increases while \( \| x_b \| \) decreases, keeping \( m_a \) and \( m_b \) constant (unless one of \( \| x_a \|, \| x_b \| \) becomes 0.5). If \( m_a = m_b \), then \( x_a, x_b \) are on the function \( f(x) = x^2 (m_a - x)^2 \), which is convex, so \( f(x_a) + f(x_b) \) also increases. Otherwise, \( m_a > m_b \), and consequently \( x_a > x_b \). Then note \( f(x_a) = x_a^2 (m_a - x_a)^2 \) and \( f(x_b) = x_b^2 (m_b - x_b)^2 \), and a quick computation finds that \( |f'(x_a)| > |f'(x_b)| \), so this also increases the sum \( f(x_a) + f(x_b) \). This process ends when \( \| x_a \| \) reaches 0.5 or when \( \| x_b \| \) reaches 0. Now we repeat this process, performing step 2 also after each iteration of this process (which reorders the integer parts). At the end, we are left with \( x_1, x_2, \dots, x_n \in \{0, 0.5, 1, 1.5, \dots, n-0.5, n\} \).

5. **Step 4: Maximizing the sum:**
   Select the largest among \( x_1, x_2, \dots, x_n \), and WLOG it is \( x_n \). For any \( x_i \in \mathbb{Z}^+ \), replace \( (x_i, x_n) \rightarrow (0, x_i + x_n) \). This clearly increases the sum \( f(x_i) + f(x_n) \). The rest of the points belong to the set \( \{0, 0.5, 1.5, \dots, n-0.5\} \), and the corresponding \( f(x_i) \) values lie on the curve \( f(x) = \frac{x^2}{4} \). This curve is convex, so the sum \( f(x_1) + \cdots + f(x_n) \) achieves a maximum when the \( x_i \) are at the (discrete) endpoints, which is when \( x_1, x_2, \dots, x_{n-2} = 0 \), \( x_{n-1} = 0.5 \), and \( x_n = n - 0.5 \).

6. **Final Calculation:**
   \[
   \sum_{i=1}^n y_i^2 = (0.5 \cdot 0.5)^2 + ((n - 0.5) \cdot 0.5)^2 = \frac{0.5^2}{4} + \frac{(n - 0.5)^2}{4} = \frac{0.25}{4} + \frac{(n - 0.5)^2}{4} = \frac{0.25 + (n - 0.5)^2}{4}
   \]
   \[
   = \frac{0.25 + n^2 - n + 0.25}{4} = \frac{n^2 - n + 0.5}{4}
   \]

The final answer is \(\boxed{\frac{n^2 - n + 0.5}{4}}\)